https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Pitel

07/22/2021, 9:07 AM
Is there some (even dumb) implementatio of
runBlocking
for JS? The project I'm working has this:
expect fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T
I tried someting like:
Copy code
var result: T? = null
val job = GlobalScope.launch { result = block }
while (!job.isCompleted) {}
return result!!
Yeah, I know it has many mistakes, but the main problem is the while loop block the execution of the coroutine.
Js runtime is non-blocking by design. Nodejs just kinda hacks it with their sync io apis
12 Views