Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to write for await ...of or AsyncGenerator in hx-jsasync? #9

Open
sonygod opened this issue Aug 19, 2021 · 3 comments
Open

how to write for await ...of or AsyncGenerator in hx-jsasync? #9

sonygod opened this issue Aug 19, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@sonygod
Copy link

sonygod commented Aug 19, 2021

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?
				
			}));

			
		});
@sonygod sonygod changed the title how to write for await ...of in hx-jsasync? how to write for await ...of or AsyncGenerator in hx-jsasync? Aug 19, 2021
@basro
Copy link
Owner

basro commented Aug 19, 2021

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)
}

@sonygod
Copy link
Author

sonygod commented Aug 20, 2021

thank you @basro , shall we keep open this until you add a new feature about for await of

@basro basro added the enhancement New feature or request label Aug 20, 2021
@basro
Copy link
Owner

basro commented Aug 20, 2021

Sure

Repository owner deleted a comment from adogmus Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants