Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/src/main/java/ru/mail/march/interactor/Interactor.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package ru.mail.march.interactor

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.*
import ru.mail.march.channel.*
import kotlin.coroutines.EmptyCoroutineContext

Expand All @@ -26,4 +23,12 @@ abstract class Interactor {
fun <T> eventChannel(): DataChannel<T> {
return channelFactory.createEventChannel()
}

fun execute(dispatcher: CoroutineDispatcher = Dispatchers.IO, block: suspend CoroutineScope.() -> Unit): Job {
return interactorScope.launch {
withContext(dispatcher) {
block.invoke(this)
}
}
}
}