Hi,
My MPP is a lib that has JVM and JS targets. The library contains an object that launches a coroutine that polls a server on an interval while (isActive). This starts up first, but, in a JS app, it seems that it blocks the application from processing anything else in the library (or the application, for that matter). I'm assuming (and I'm not a JavaScript expert, nor do I intend to be) that the polling is blocking the main thread in Node, since when I disable that object, things seem to flow fine.
Is my assessment correct? If so, what patterns/best practices can I use to solve for this?
Thanks!
u
uli
10/13/2021, 7:51 PM
How do you implementation the interval?
Js is single threaded. You must use delay for waiting
a
Alfred Lopez
10/13/2021, 7:53 PM
I do use delay
u
uli
10/13/2021, 7:55 PM
Then show us some code đŸ™‚
a
Alfred Lopez
10/13/2021, 7:56 PM
Copy code
protected val pollingJob = SupervisorJob()
protected val scope = CoroutineScope(Dispatchers.Default + pollingJob)
override fun start() {
<http://logger.info|logger.info>({ "Launching listener polling..." })
scope.launch(errorHandler) {
started = true
do {
if (!polling) doPoll()
delay(pollingInterval * ONE_SECOND)
} while (this.isActive)
}
<http://logger.info|logger.info>({ "Started listener polling..." })
}
u
uli
10/13/2021, 7:59 PM
Looks good. Are you sure it is not poll that is blocking?
a
Alfred Lopez
10/13/2021, 8:01 PM
Maybe. Let me get back to you in a bit…
Alfred Lopez
10/14/2021, 12:39 AM
@uli it seems that doPost is the culprit, specifically at the await() point of an async call. I have two of them because I want to call two services in "parallel". When it hits the await(), it hangs there.