Hi, My MPP is a lib that has JVM and JS targets. ...
# javascript
a
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
How do you implementation the interval? Js is single threaded. You must use delay for waiting
a
I do use delay
u
Then show us some code đŸ™‚
a
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
Looks good. Are you sure it is not poll that is blocking?
a
Maybe. Let me get back to you in a bit…
@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.