Search code examples
javascriptnode.jsasync-awaitgenerator

How to declare async generator function


I am trying to create async generator function in Node.js, but it seems to be impossible.

Version of my Node.js: 7.6.0.

My code:

async function* async_generator(){
  for(let i = 0; i < 10; i++){
    yield await call_to_async_func(i);
  };
}

Error I got:

enter image description here

Does anyone knows what is the problem? Why I can't create async generator function while I can create generator function or async function Independently?


Solution

  • There simply are no asynchronous generator functions in Node.js.

    Yet. They're still figuring out what their semantics would be, see the async iteration proposal.