https://kotlinlang.org logo
#javascript
Title
# javascript
a

Andrey Tabakov

07/20/2022, 2:10 PM
Hi, I have a question about suspend function in JS Is there a way to sync asynchronous code in Kotlin/JS? In koltin/JVM we can use
runBlocking
Something like this (not working of course)
Copy code
fun notSuspendedFunction(block: suspend () -> T): String {
   
  val result = await block() // or runBlocking { block() }
 
  return result
}
I'm okay with something like this (not working of course):
Copy code
fun notSuspendedFunction(block: suspend () -> T): String {
  val job = GlobalScope.async { block() }

  while(job.isCompleted) { /* may be set timeout or something with delay */ }

  return job.getCompleted()
}
🚫 5
👍 1
s

Shumaf Lovpache

07/20/2022, 3:17 PM
Structured concurrency is one of the questions that still needs to be worked on. So yeah, the first idea that came is something like what you presented above
5 Views