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

Nikky

12/23/2020, 10:28 PM
so i know i cannot block on javascript.. but does anyone have a snippet for kotlin-js that does approximately the same thing as runBlocking and returning the result ? something like
Copy code
val derferred = async {  ... }
while(!deferred.isCompleted) {
   delay(10)
}
return deferred.getCompleted()
except since i am not in a coroutine i cannot use delay outside of it..
m

Marc Knaup

12/23/2020, 10:31 PM
Well, you already know the answer 😉 Not possible.
n

Nikky

12/23/2020, 10:35 PM
how would one then implement things like initlaizing dependencies in eg. koin in a
() -> T
? if there was a callback or such i could do
.then
..
m

Marc Knaup

12/23/2020, 11:48 PM
Dependencies are initialized synchronously. No coroutines, no async code.
b

Big Chungus

12/24/2020, 9:14 AM
My advice would be to have your entire app in suspend scope. Starting with "suspend fun main() {}"
If you really want to have something "blocking" you can implement it with while loop polling for completion
7 Views