Maciek
07/22/2020, 6:24 AMoctylFractal
07/22/2020, 6:26 AMblock()
takes 5ms to execute, you want it run again in 5ms), noScheduledExecutorService
differs between these with the terms "fixed rate" and "fixed delay" -- your current example is "fixed delay", not "fixed rate"Maciek
07/22/2020, 6:28 AMmeasureTimeMillis
to achieve fixed rateoctylFractal
07/22/2020, 6:29 AMMaciek
07/22/2020, 6:29 AMoctylFractal
07/22/2020, 6:30 AMMaciek
07/22/2020, 6:35 AMwasyl
07/22/2020, 7:02 AMlaunch { interval(123) { doX() } }
, right?
suspend fun interval(time: Long, block: suspend () -> Unit) {
while (true) {
block()
delay(time)
}
}
I’m still kind of confused when to prefer an extension on CoroutineScope
(or is passing scope better?) vs having a suspend fun
octylFractal
07/22/2020, 7:04 AMCoroutineScope
are for "forking" a new coroutine that runs async, suspend fun
is for normal sync behaviorwasyl
07/22/2020, 7:12 AMfun CoroutineScope.doX()
vs fun doX(scope: CoroutineScope)
- implementing CoroutineScope
by a class vs keeping the scope in a field (as long as I implement scope only for convenience, e.g. to call launch
easily)octylFractal
07/22/2020, 7:12 AM