is there any way to leverage webworkers when using...
# coroutines
t
is there any way to leverage webworkers when using coroutines on javascript?
g
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
alroght thank you 🙂