is there a way to schedule a block of code to run ...
# coroutines
v
is there a way to schedule a block of code to run on a block completion when run with
withContext
? (I’m trying to time some functions)
along the same lines, would using
invokeOnCompletion
with async be a “good” idea
r
Not sure exactly what the use case is but maybe try
runBlocking
?
d
What does "to run on a block completion" mean?
s
Copy code
suspend fun someFun() = withContext(<http://Dispatcher.IO|Dispatcher.IO>) {
 …
}
or
coroutineScope
, please, use it, if you are able to call it from coroutine/suspend fun, as
runBlocking
is blocking, and
coroutineScope
is suspending
v
@Dominaezzz,
withContext
takes a parameter `block`; that block’s completion; think of it like
Copy code
try {
   block()
} finally {
   method()
}
d
Oh, "block" -> "block's". Got it.
You can put
withContext
in try/finally, no?
v
hmm, withContextTimed with the same arguments, cool
will try that