elizarov
01/17/2017, 9:33 AMelizarov
01/17/2017, 9:34 AMkotlinx.coroutines
(to be released soon) will support the concept of the default context.elizarov
01/17/2017, 9:35 AMkotlinx.coroutines
builders to do some work in parallel will automatically inherit the context.elizarov
01/17/2017, 9:36 AMrunSuspending(CoroutineName("MyName")) { ... }
.voddan
01/17/2017, 10:25 AMrunSuspending
will mainly be hidden by a particular framework with all the characteristics of the framework hidden in the context, but the end user will be able to freely mix frameworks by mixing contexts?elizarov
01/17/2017, 10:26 AMelizarov
01/17/2017, 10:26 AMrunSuspending
in kotlinx.coroutines
will understand the concept of the current context, so you can use runSuspending
to "fire-and-forget"new coroutine in the current context.elizarov
01/17/2017, 10:27 AMflatMap
operation for rx.Observable
(if it were not already there):elizarov
01/17/2017, 10:30 AMfun <T> Observable<Observable<T>>.flatMap() = observable { // use a coroutine builder to build observable by yielding values
for (obs in this) { // use suspending iteration extension on observable
runSuspending { // run a fresh coroutine for each obs: Observable<T>
for (element in obs) { // now iterate on the element of obs in a separate coroutine
yield(element) // yield to result
}
}
}
}
elizarov
01/17/2017, 10:31 AMrunSuspending
if you just need to do stuff in parallel with whatever else you were doing in the same context.elizarov
01/17/2017, 10:31 AMrunSuspending
will be an end-user primitivevoddan
01/17/2017, 10:32 AMelizarov
01/17/2017, 10:32 AMvoddan
01/17/2017, 10:32 AMelizarov
01/17/2017, 10:32 AMkotlinx.coroutines
elizarov
01/17/2017, 10:32 AMelizarov
01/17/2017, 10:34 AMrunSuspending
will be somewhat like:
fun runSuspending(context: CoroutineContext = EmptyContext, block: suspend () -> Unit) {
val actualContext = currentContext + context
// now use actualContext to start coroutine
}
teedee
01/17/2017, 10:34 AMkotlinx.coroutines
and their behaviour would depend on the contexts that are passed to it?elizarov
01/17/2017, 10:35 AMelizarov
01/17/2017, 10:35 AMelizarov
01/17/2017, 10:37 AMrunSuspending(Swing) { ... }
or runSuspending(MyComputePool) { ... }
with ease.elizarov
01/17/2017, 10:38 AMrunSuspending
is a simple builder you might say, but there are bunch more complicated ones, and I don't want to cut-and-paste all of them. Especially, if you take into an account a variety of futures/promises implementation. There will be a builder for each one of them! I want to compose any builder with any context.elizarov
01/17/2017, 10:39 AMcurrentContext
? E.g. what shall be the default behavior of runSuspending
be? Shall it, by default, use an empty context or inherit the context of the parent coroutine?elizarov
01/17/2017, 10:40 AMSwing
. They are essential for debugging.elizarov
01/17/2017, 10:40 AMelizarov
01/17/2017, 10:42 AMelizarov
01/17/2017, 10:43 AMkotlinx.coroutines
is going to provide some facilities to name coroutines, cancel coroutines, give then identity!elizarov
01/17/2017, 10:44 AMelizarov
01/17/2017, 10:45 AMrunSuspending
. It is imperative that is inherits the contest of the coroutine that processes the request, so that it is cancelled as soon as the request is completed for any reason.elizarov
01/17/2017, 10:48 AMrunSuspending(Lifetime()) { ... }
, so you construct a fresh lifetime for that coroutine explicitly, that is not bound to the lifetime of the current coroutine.