I'm working on a code that sends subscription mess...
# javascript
t
I'm working on a code that sends subscription messages from the browser to the server periodically, let's say in every 30 seconds. The messages are generated by a coroutine, using delay to wait between messages. The problem is that Safari and Chrome stops the coroutine after a minute or so if the browser is in the background or minimized. As far as I know the solution would be web workers, but it would be very inconvenient to split the code because of this. Any ideas / pointers which way should I go?
a
I looked into Web Workers recently for a different task, and I found you can create them inline without a separate file. https://stackoverflow.com/questions/5408406/web-workers-without-a-separate-javascript-file It turned out that Web Workers didn’t solve my problem so I didn’t use them, but from memory a basic test worked
thank you color 1
this blog post was helpful too in showing how to use Web Workers in Kotlin/JS. It also shows how to split the worker into a separate source set https://avwie.github.io/multithreaded-web-applications-in-kotlin-with-web-workers
t
Wow! This is a great post, thanks for sharing.
a
you’re welcome :)