Paul Woitaschek
02/23/2017, 11:49 AMPaul Woitaschek
02/23/2017, 11:58 AMPaul Woitaschek
02/23/2017, 12:58 PMgildor
02/23/2017, 1:10 PMmight make sense to create a wrapping class that encapsulates the error / sucess@Paul Woitaschek I use this approach for my coroutine wrapper for Retrofit: https://github.com/gildor/kotlin-coroutines-retrofit#awaitresult
.await
returns sealed class ResultPaul Woitaschek
02/24/2017, 10:34 AMnimtiazm
02/25/2017, 10:04 AMPaul Woitaschek
02/26/2017, 12:12 PMPaul Woitaschek
02/28/2017, 10:28 AMfrankdavid
02/28/2017, 12:52 PMkirillrakhman
03/01/2017, 2:56 PMgildor
03/01/2017, 3:46 PMkotlinx-coroutines
be published to jcenter? I’m updating library but still cannot use kotlinx-coroutines without maven { url "<https://dl.bintray.com/kotlin/kotlin-eap-1.1>" }
kevinherron
03/01/2017, 9:11 PMgroostav
03/02/2017, 12:22 AMRestrictsSuspension
😞robin
03/02/2017, 8:54 AMelizarov
03/02/2017, 1:46 PMelizarov
03/03/2017, 4:43 PMrakshakhegde
03/04/2017, 4:43 AMkingsley
03/04/2017, 7:35 AM// File A: Some repository
fun fetchFooAsync = async(CommonPool) { ... }
// File B: Android activity
private val job = Job()
fun loadFooIntoUI() {
launch(Android + job) {
fetchFooAsync().await()
...
}
}
When the activity in B is getting destroyed, I can easily call job.cancel()
, and the coroutine in loadFooIntoUI
is canceled correctly. However, the fetchFooAsync
call still continues indefinitely.
Is there a way to neatly cancel everything altogether without having to explicitly pass job
to fechFooAsync
?kingsley
03/04/2017, 8:03 AMinvokeOnCompletion
to the returned Job for launch
, but that takes away the fun since I have to repeat it everywherev0ldem0rt
03/04/2017, 8:21 AMelizarov
03/04/2017, 3:18 PMoshai
03/04/2017, 5:34 PMjw
03/04/2017, 7:18 PMelizarov
03/04/2017, 8:50 PMcedric
03/05/2017, 4:05 AMelizarov
03/05/2017, 7:09 AMConcurrentHashMap
is better.elizarov
03/05/2017, 12:18 PMAsync
in the name of suspending function. This naming is better to be reserved for functions that start asynchronous operation and return immediately, usually with some kind of future/deferred result. The async part the name serves as a reminder to the invoker of this function that they should not ignore the result, but must await for it or compose it into a larger computation in some way. There is no such risk with suspending functions, and the async in their name is superfluous.deviant
03/05/2017, 4:14 PMfun dataChannel(context: CoroutineContext) = produce<Any>(context) {
val listener = object : Listener {
override fun onSuccess(value: Any) {
offer(value) // emit to channel
}
override fun onError(throwable: Throwable) {
close(throwable) // close channel
//throw throwable
}
}
addListener(listener)
fetchData() // invoke callback's onResult here
// need to register removeListener() somewhere
}
v0ldem0rt
03/06/2017, 5:40 AMadambl4
03/06/2017, 12:00 PMsuspend fun Completable.await()
since rx.Completable has a member function with the same name?adambl4
03/06/2017, 12:00 PMsuspend fun Completable.await()
since rx.Completable has a member function with the same name?elizarov
03/06/2017, 12:05 PMCompletable.await
from Rx 1.x module. It is not a problem with Rx 2.x. It does not have this name conflict (there is no Completable.await
there)bamdmux
03/06/2017, 12:19 PMelizarov
03/06/2017, 12:22 PMawait
seems to be a more natural name and you already get a visual cue in IDE that this is a suspending invocation going on.bamdmux
03/06/2017, 12:33 PMelizarov
03/06/2017, 12:45 PMdevelop
branch, though, — there is a bug in master version of Rx2 Completable.await)