(ES6) ES6 (2016)

SymbolAsyncIterator (SA01)

   1:  const asyncIterable = {
   2:      [Symbol.asyncIterator]: async function* () {
   3:          yield await Promise.resolve(1);
   4:          yield await Promise.resolve(2);
   5:          yield await Promise.resolve(3);
   6:      }
   7:  };
   8:  
   9:  (async () => {
  10:      for await (const value of asyncIterable) {
  11:          console.log(value); // 1, then 2, then 3
  12:      }
  13:  })();



It's used when you want an object to be asynchronously iterable (usable with for await...of loops).

1
2
3





SymbolAsyncIterator context:






ES6 context:



Comments ( )
Link to this page: http://www.vb-net.com/JavascriptES6/SA01.htm
< THANKS ME>