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

Updated on: 12-Jun-2020

129 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements