From e2e47af2c85c213f8a597eeb14b1a3ceb87d5839 Mon Sep 17 00:00:00 2001 From: "a.fialko" Date: Tue, 31 Aug 2021 00:05:39 +0300 Subject: [PATCH 1/2] execute api --- .../java/ru/mail/march/interactor/Interactor.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/ru/mail/march/interactor/Interactor.kt b/core/src/main/java/ru/mail/march/interactor/Interactor.kt index 119a0c9..1c8e118 100644 --- a/core/src/main/java/ru/mail/march/interactor/Interactor.kt +++ b/core/src/main/java/ru/mail/march/interactor/Interactor.kt @@ -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 @@ -26,4 +23,12 @@ abstract class Interactor { fun eventChannel(): DataChannel { return channelFactory.createEventChannel() } + + fun execute(dispatcher: CoroutineDispatcher = Dispatchers.IO, block: suspend CoroutineScope.() -> Unit) { + interactorScope.launch { + withContext(dispatcher) { + block.invoke(this) + } + } + } } \ No newline at end of file From bfab89ea918419e00f7a78426b45f5ff7e1b8faf Mon Sep 17 00:00:00 2001 From: "a.fialko" Date: Tue, 31 Aug 2021 00:18:29 +0300 Subject: [PATCH 2/2] return job on execute --- core/src/main/java/ru/mail/march/interactor/Interactor.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/ru/mail/march/interactor/Interactor.kt b/core/src/main/java/ru/mail/march/interactor/Interactor.kt index 1c8e118..7ee10b7 100644 --- a/core/src/main/java/ru/mail/march/interactor/Interactor.kt +++ b/core/src/main/java/ru/mail/march/interactor/Interactor.kt @@ -24,8 +24,8 @@ abstract class Interactor { return channelFactory.createEventChannel() } - fun execute(dispatcher: CoroutineDispatcher = Dispatchers.IO, block: suspend CoroutineScope.() -> Unit) { - interactorScope.launch { + fun execute(dispatcher: CoroutineDispatcher = Dispatchers.IO, block: suspend CoroutineScope.() -> Unit): Job { + return interactorScope.launch { withContext(dispatcher) { block.invoke(this) }