Nikky
07/31/2020, 3:59 PMsuspend fun
?streetsofboston
07/31/2020, 4:05 PMsuspend fun fromSomeManagerCallback(): SomeResult = suspendCancellableCoroutine { cont ->
someManager.setCallback { result ->
cont.resume(result)
}
}
Nikky
07/31/2020, 4:07 PMstreetsofboston
07/31/2020, 4:08 PMsetCallback
will be called no more than once.Nikky
07/31/2020, 4:58 PMNikky
07/31/2020, 4:58 PMstreetsofboston
07/31/2020, 5:14 PMcont.resumeWithException(error)
Nikky
07/31/2020, 5:18 PMonCancellation
callbackstreetsofboston
07/31/2020, 5:51 PMonCancellation
callback to the someManager
in my example-snippet?streetsofboston
07/31/2020, 5:53 PMcont.resume
just needs one parameter; the result value (an instance of SomeResult
in my example-snippet).streetsofboston
07/31/2020, 5:56 PMresume
on a Continuation
. Use the one that does not have the onCancellation
parameter. It is the one that is an extension function on Continuation:
public inline fun <T> Continuation<T>.resume(value: T): Unit
Nikky
07/31/2020, 7:16 PMstreetsofboston
07/31/2020, 7:28 PMNikky
07/31/2020, 7:35 PMstreetsofboston
07/31/2020, 7:44 PMcollect
function on a `Flow`….