jw
09/06/2017, 12:48 PMkevinherron
09/06/2017, 3:34 PMdeviant
09/07/2017, 11:57 AMkotlin-coroutines-retrofit
lib?
private fun Call<*>.registerOnCompletion(continuation: CancellableContinuation<*>) {
continuation.invokeOnCompletion {
if (continuation.isCancelled)
try {
cancel() // why to cancel already cancelled coroutine?
} catch (ex: Throwable) {
//Ignore cancel exception
}
}
}
groostav
09/08/2017, 9:58 PMProvider<Channel>
elizarov
09/11/2017, 7:31 AMUnconfined
context, which leaves the thread “unspecified”.elizarov
09/11/2017, 12:06 PMEmptyCoroutineContext
and Unconfined
are virtually the same with the exception that Unconfined
is designed to work with debugging facilities of kotlinx.coroutines
(in debug mode you’ll get the id of the executing coroutine added to the thread name — wastes a lot of CPU, but simplifies debugging)jw
09/11/2017, 9:17 PMChannelIterable
that has fun iterator(): ChannelIterator<T>
?gildor
09/14/2017, 7:30 AMelizarov
09/14/2017, 7:48 AMlaunch
is just like starting a new thread. If the code inside launch
crashes with exception then it is considered “uncaught” exception and, generally, should crash your app (on Android that happens automatically). However, when you use async
and the execution results with exception, then this exception gets stored inside the Deferred
. It is your obligation to process it later. So:
- launch
- fire and forget, crash application on uncaught error;
- async
- launch and await
for result later. You must await
on a coroutine that you’ve created with async
. You MUST NOT forget about the coroutine you’ve started with async.gildor
09/14/2017, 8:13 AMelizarov
09/14/2017, 9:15 AMkotlinx.coroutines
is because we are still evolving it and bits of syntax and behavior might change from release to release. It is easier to keep docs versioned together with sources (both guides and kdocs). You cannot do this with wikis. Risks are high you will end up with outdated wikis (for example, CoroutineScope.context
was deprecated recently, renamed to coroutineContext
— it was easy to push it into all the guides and kdocs with a single commit)elizarov
09/15/2017, 4:57 PMkotlinx.coroutines
. Parent will always wait for its children to complete. Details of the change are here: https://github.com/Kotlin/kotlinx.coroutines/issues/125 Please, comment if you don’t think it is a good idea.mingkangpan
09/17/2017, 9:46 PMraulraja
09/17/2017, 9:53 PMblocking
but if not you should probably create a Pool that is tunned up for this type of ops usually DB calls, network IO, etc...elizarov
09/18/2017, 7:45 AMdeviant
09/18/2017, 3:25 PMChannel
into Sequence
? is it possible? something like that
produce<Int>{
send(1)
send(2)
send(3)
}
.asSequence() // some suspendable helper?
.filter {it==1}
Gary Tierney
09/18/2017, 11:29 PMelizarov
09/19/2017, 7:18 PMkingsley
09/22/2017, 11:43 AMlaunch
? Yes, we can. You simply run it within a runBlocking
and await
it’s completion (or termination as the case may be)
However the UI
makes it difficult to unit test without bringing all the platform dependency with it.
I would abstract this part out instead, to make it easy to swap with a non-platform dependent coroutineContextelizarov
09/22/2017, 8:09 PMN
worker coroutines that all take tasks from this channel and do your http calls. The number of coroutines you have limits the number of concurrent HTTP requests without having you think about threads at all. In fact, if your HTTP library is truly async, they can all simply run a single thread, yet still giving you control over maximal concurrency.kirillrakhman
09/24/2017, 6:07 PMkioba
09/25/2017, 3:52 PMgildor
09/25/2017, 11:34 PMgildor
09/26/2017, 7:20 AMPaul Woitaschek
09/26/2017, 7:22 AMelizarov
09/26/2017, 7:35 AMrun(UI)
for them just to make sure they are on the right thread (it will not switch if you invoke them from the right thread). Ideally, we should have tooling where you’d annotate your UI functions with @UI
(or even better — make this annotation inferred by looking at their code and seeing that they use some other UI-thread-only functions) and then it would warn you if you try to use them from the wrong context…. Just an idea.Paul Woitaschek
09/26/2017, 7:36 AMkotlin.run
voddan
09/26/2017, 10:51 AMrun
builder function function to a less confusing name? Gonna vote on thatdave08
09/26/2017, 2:56 PMpablisco
09/26/2017, 11:17 PMpablisco
09/26/2017, 11:17 PMgildor
09/27/2017, 1:48 AMpablisco
09/27/2017, 6:02 AMgildor
09/27/2017, 6:04 AM