Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

async_iterator.js 670B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. // async function* asyncIterator() {
  3. // while (true) {
  4. // const value = await this.next();
  5. // if (!value) {
  6. // await this.close();
  7. // return;
  8. // }
  9. // yield value;
  10. // }
  11. // }
  12. // TODO: change this to the async generator function above
  13. function asyncIterator() {
  14. const cursor = this;
  15. return {
  16. next: function() {
  17. return Promise.resolve()
  18. .then(() => cursor.next())
  19. .then(value => {
  20. if (!value) {
  21. return cursor.close().then(() => ({ value, done: true }));
  22. }
  23. return { value, done: false };
  24. });
  25. }
  26. };
  27. }
  28. exports.asyncIterator = asyncIterator;