ansman
02/07/2019, 2:25 AMsuspend fun performHeavyWork()
Would it be advisable to use an actor for this case? The callee should be able to receive a progress value between 0-1 (or 0-100).octylFractal
02/07/2019, 2:38 AMproducer
here -- the function can return ReceiveChannel<Int>
, which the callee can use to get progress values. Of course, this won't work if you want to return something else, in which case I would make a sealed class, something like Event
with Progress
and Result
subclasses. Then you can send progress events until you are done, and send a result event with the final data.gildor
02/07/2019, 2:47 AMansman
02/07/2019, 12:05 PMgildor
02/07/2019, 12:17 PMgildor
02/07/2019, 12:17 PMgildor
02/07/2019, 12:18 PMsuspend fun doSomething(progress: ((Float) -> Unit)? = null): SomeResult
gildor
02/07/2019, 12:19 PMansman
02/07/2019, 1:11 PMansman
02/07/2019, 1:11 PMbdawg.io
02/07/2019, 4:39 PMwithContext
and then launch
invocations of your progress callback so it doesn’t block your doSomething
from moving forward while progress notification is consumedoctylFractal
02/07/2019, 6:57 PMoctylFractal
02/07/2019, 6:58 PMansman
02/07/2019, 7:00 PMoctylFractal
02/08/2019, 12:14 AMThe running coroutine is cancelled when its receive channel is cancelled.additionally, calling
receiveOrNull
suspends until done if no more progress is being made