What are async generator methods in JavaScript?



Async generator functions are the same like generator function. The async generator functions will return an object, whereas an async generator whose methods such as next, throw and return promises for { value, done }, instead returning directly.

Example

Here’s an example from GitHub showing function returning async generator object −

async function* readLines(path) {
   let file = await fileOpen(path);
      try {
         while (!file.EOF) {
            yield await file.readLine();
         }
      } finally {
      await file.close();
   }
}
raja
Published on 25-Jan-2018 11:22:42
Advertisements