Hi - I'm using a library which provides me an asyn...
# javascript
m
Hi - I'm using a library which provides me an async iterator. I'm unsure how to model
for await...of
in kotlin/js. here is the pure js sample code
const sub = await this.nats.jetstream().subscribe(subject, opts)
for await(const m of sub) {  // what's the kotlin/js equivalent
const data = this.jc.decode(m.data)
switch (data.type) {
case "draw":
break;
case "clear":
log("clear")
default:
break;
}
}
Would appreciate any pointers or examples.
t
сс @Sergei Grishchenko
j
you'll need to implement a scope for it first see https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/promise.html then you can call suspending functions just like you would in JVM or Android Kotlin
t
Looks like function
sub
- AsyncIterable
m
Thank you.
t
Since
pre.556
AsyncIterable.iterator
extension is available
for
must work fine