simon.vergauwen
01/03/2019, 7:27 PMDeferred<A>
NonCancelable
by wrapping and awaiting it in a withContext
block like below. And how does its scope get (re)wired correctly? Snippet seems to work although I don't quite understand it.
val def = thisWasPassedToMe()
val result = withContext(NonCancelable) {
def.await()
}
bdawg.io
01/03/2019, 7:31 PMCancellationException
thrown if the backing Job for def
gets cancelledbdawg.io
01/03/2019, 7:31 PMNonCancellable
will just make sure that your withContext
itself doesn’t exit from being cancelled itselfsimon.vergauwen
01/03/2019, 7:34 PMwithContext
is NonCancelable?simon.vergauwen
01/03/2019, 7:35 PMbdawg.io
01/03/2019, 7:44 PMDeferred
is just a reference handle to the state of the coroutinesimon.vergauwen
01/03/2019, 7:51 PMgroostav
01/03/2019, 9:06 PMlaunch
or runBlocking
you can use CoroutineStart.ATOMIC
groostav
01/03/2019, 9:06 PMlaunch(CoroutineStart.ATOMIC){
val def = thisWasPassedToMe()
def.await()
}
groostav
01/03/2019, 9:08 PMsuspend fun doStuffWithThingPassedToMe(){
try {
val def = thisWasPassedToMe()
}
finally {
//this will fire in all cercomstances (except abandonment!)
}
}
simon.vergauwen
01/03/2019, 9:13 PMsimon.vergauwen
01/03/2019, 9:16 PMDeferred
is guaranteed to have never run.groostav
01/03/2019, 9:23 PMrelease
?groostav
01/03/2019, 9:24 PMsimon.vergauwen
01/03/2019, 9:26 PMDeferred<A>
that has never run and is lazily run.simon.vergauwen
01/03/2019, 9:27 PMrelease
is guaranteed to be called. There is also a use
function which you can use to consume the `acquire`d resource.simon.vergauwen
01/03/2019, 9:28 PMDeferred
to safely consume and release resources with a guarantee not to leak.simon.vergauwen
01/03/2019, 9:29 PMObservable
, Flux
, IO
, …simon.vergauwen
01/03/2019, 9:30 PM