I wonder if there is still an interest in web work...
# javascript
e
I wonder if there is still an interest in web workers / worker threads from the KJS team. https://github.com/Kotlin/KEEP/blob/master/notes/web-workers.md As of now I can't find any resource on how to use workers in a Node.js library. I'm also open to strange workarounds.
a
there are a couple of useful links in this thread: https://kotlinlang.slack.com/archives/C0B8L3U69/p1688198822341369
e
Thanks Adam, reading now
👍 1
Cool blog post! I think it can be adapted to Node.js fairly easily
🚀 1
Luckily the bundle size is not a concern for me, as the library will be pretty big anyway. I didn't know you could have different compilations (like, two
js
blocks), have you ever used it that way? Apart from this use case, I can't see how it might be useful
a
yes it's a bit unusual, but it can be useful if you really need fine grained control. I've experimented with it before for splitting up Node/Browser sources https://youtrack.jetbrains.com/issue/KT-47038/KJS-MPP-Split-JS-target-into-JsBrowser-and-JsNode#focus=Comments-27-7501103.0-0, and Coroutines do it to split out JDK8 functionality https://github.com/Kotlin/kotlinx.coroutines/blob/f227432328afe41505a62a9fa6ee9d12ae6aab80/kotlinx-coroutines-core/build.gradle#L24-L41 (though I think this is a legacy set up and not used any more)
e
Thanks. Upvoted the issue btw, I also wanted the separation.
I wonder tho why the splitting (different compilations) doesn't solve the issue, doesn't it let you specify different dependencies, and different target distributions?
a
I used web workers in a demo, but it’s browser based. https://avwie.github.io/multithreaded-web-applications-in-kotlin-with-web-workers
e
Oh that was the blog post linked by Adam, nice work btw
a
Haha okay! 😂 Double link drop then. I think web workers actually work quite nice. We’re experimenting with having web workers in Kotlin for our domain logic, but react hooks for the frontend to call them. It’s not really a lot different from using a normal request response flow.
e
I'll see if I can adapt your code to spawn worker threads in Node.js. The basics seem pretty much the same, just different function calls