You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
How does the function elementScope() work and when does it end?
According to my understanding, the coroutines from elementScope() run as long as the associated page is active. When the page is closed, the ElementScope also ends, along with the coroutines contained within it. Is this correct?
My tests have shown that this doesn't work as such. Below is an example of a simple implementation. When the page is opened, a label that is continuously updated by a coroutine in ElementScope is displayed. If I refresh the page in the browser, a second coroutine starts, and the original one continues to run. I would have expected that the original coroutine would end when the page is closed.
I have found out that the coroutine is ended when the function browser.callJsFunctionWithResult("") is called within it.
My goal is to have a coroutine on the page run as long as the element to be updated exists. It should carry out a kind of polling on an external resource. If the element no longer exists, the coroutine should be ended. How can I implement this?
importkotlinx.coroutines.*importkweb.Kwebimportkweb.labelimportjava.awt.Desktopimportjava.net.URIimportjava.util.concurrent.atomic.AtomicIntegerclassWebserverCoroutineTest {
val coroutineId =AtomicInteger(0)
@org.junit.Testfuntest1() {
runBlocking {
Kweb(port =16097, debug =true) {
doc.body {
/* get ID of the thread */val id = coroutineId.incrementAndGet()
/* Add Label to Page */val labelText = kvar("")
label().text(labelText)
/* Update the label every 100ms and print Coroutine Id */
elementScope().launch {
while (isActive) {
// if this is called, the Coroutine quits, if the WS session is disconnected
browser.callJsFunctionWithResult("")
val newText ="Coroutine $id: ${System.currentTimeMillis()}"println(newText)
labelText.value = newText
delay(100)
}
}
}
}
Desktop.getDesktop().browse(URI("http://localhost:16097"))
// wait for 10 minutes
delay(1000*60*10)
}
}
}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
How does the function
elementScope()
work and when does it end?According to my understanding, the coroutines from
elementScope()
run as long as the associated page is active. When the page is closed, theElementScope
also ends, along with the coroutines contained within it. Is this correct?My tests have shown that this doesn't work as such. Below is an example of a simple implementation. When the page is opened, a label that is continuously updated by a coroutine in
ElementScope
is displayed. If I refresh the page in the browser, a second coroutine starts, and the original one continues to run. I would have expected that the original coroutine would end when the page is closed.I have found out that the coroutine is ended when the function
browser.callJsFunctionWithResult("")
is called within it.My goal is to have a coroutine on the page run as long as the element to be updated exists. It should carry out a kind of polling on an external resource. If the element no longer exists, the coroutine should be ended. How can I implement this?
The text was updated successfully, but these errors were encountered: