Hi, I have a question about suspend function in JS...
# javascript
a
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
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