Bernhard
07/10/2024, 8:06 PMturansky
07/10/2024, 8:30 PMsuspend
functions, lambdasBernhard
07/10/2024, 8:36 PMBernhard
07/10/2024, 8:37 PMturansky
07/10/2024, 8:39 PMfun func(
p: String,
block: suspend () -> Unit,
) {
// your code
}
Bernhard
07/10/2024, 8:39 PMBernhard
07/10/2024, 8:40 PMturansky
07/10/2024, 8:41 PMasync
function = function, which returns Promise
- no magicBernhard
07/10/2024, 8:41 PMBernhard
07/10/2024, 8:42 PMfunc("param") {
fetch("url").await()
}
Bernhard
07/10/2024, 8:43 PMfunc("param", async () => { await fetch("url") })
turansky
07/10/2024, 8:44 PMfunc("param") {
GlobalScope.promise {
fetch("url")
}
}
Bernhard
07/10/2024, 8:45 PMBernhard
07/10/2024, 8:46 PMBernhard
07/10/2024, 8:47 PMBernhard
07/10/2024, 8:47 PMturansky
07/10/2024, 8:49 PMBernhard
07/10/2024, 8:50 PMBernhard
07/10/2024, 8:51 PMturansky
07/10/2024, 8:52 PMturansky
07/10/2024, 8:55 PMfun <T> buildPromise(
block: suspend () -> T,
): Promise<T> =
CoroutineScope(EmptyCoroutineContext).promise(block = block)
turansky
07/10/2024, 8:56 PMBernhard
07/10/2024, 8:56 PMBernhard
07/10/2024, 8:56 PMturansky
07/10/2024, 9:08 PMasync
lambda in JS will give you isolated error context.
Similar task in Kotlin can be solved with isolated coroutine scope (not global).
I personally don't have use cases for GlobalScope