Do I have to define them externally like so:
external fun setTimeout(exec: suspend () -> Unit, timout: Int)
Or is there something in the stdlib I can use?
I can't use kotlin.browser.window.setTimeout because I want to run it with nodejs.
Do I have to define them externally like so:
external fun setTimeout(exec: suspend () -> Unit, timout: Int)
Or is there something in the stdlib I can use?
I can't use kotlin.browser.window.setTimeout because I want to run it with nodejs.
There is already a setTimeout
function in kotlin-stdlib-js
. You don't need to declare it externally. The usage is pretty straightforward:
import kotlin.browser.window
fun main() {
window.setTimeout(handler = { window.alert("Timed out!") }, timeout = 1000)
}
This will alert you (another well-known JS function) after 1 second, as expected.
kotlinx.browser.window
–
Ternate It's definitely not in the stdlib. I'm doing the same thing, defining the external functions I need.
external fun setTimeout(handler: dynamic, timeout: Int = definedExternally, vararg arguments: Any?): Int
You have
external fun setTimeout(
callback: () -> Unit,
ms: Int = definedExternally,
): Timeout
and you can use it like this : setTimeout({ if(someCondition) doSomething() }, 3000)
© 2022 - 2024 — McMap. All rights reserved.