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

thana

03/10/2019, 3:52 PM
is there any way to leverage webworkers when using coroutines on javascript?
g

gildor

03/10/2019, 5:00 PM
You can use JS webworkers API from Kotlin JS, there are some Js libraries that provide promise based API for webworkers, so you can use coroutines (using
promise.await()
)
But there are no special facilities that would allow you to run some arbitrary coroutine code on webworker (like special dispatcher, similar to what you can do on JVM with threads), in theory something like this possible, but problem how to pass code to worker (again, probably it's possible to do, using some serialization, but nothing like this available now as I know), so for now you have to do that manually: write client code and worker code separately and use messages/promises to communicate between them
t

thana

03/10/2019, 7:12 PM
alroght thank you 🙂
17 Views