hx-jsasync
hx-jsasync copied to clipboard
how to write for await ...of or AsyncGenerator in hx-jsasync?
how to write haxe code eq
for await (const msg of source) {
// exact matching
node2.handle('/your-protocol', ({ stream }) => {
pipe(
stream,
async function (source) {
for await (const msg of source) {
console.log(msg.toString())
}
}
)
})
how to support AsyncGenerator?
node.handle('/your-protocol', (d) -> {
ItPipe.pipe(d.stream, JSAsync.jsasync(function(source:Array<Promise<Any>>) {
//don't know how to write here?
}));
});
hx-jsasync doesn't currently support for await. It might be a good feature to include in the future.
In your example code the source argument of your function is an Array and not an async iterator/generator. If so you can simply do:
for (v in source) {
Browser.console.log(msg.jsawait());
}
However, if your source is an async iterator you'll need to write the loop manually:
while(true) {
var v = source.next().jsawait();
if ( v.done ) break;
Browser.console.log(v.value)
}
thank you @basro , shall we keep open this until you add a new feature about for await of
Sure