TaskQueue.js 301 B

1234567891011121314151617
  1. class TaskQueue {
  2. constructor() {
  3. this._chain = Promise.resolve();
  4. }
  5. /**
  6. * @param {Function} task
  7. * @return {!Promise}
  8. */
  9. postTask(task) {
  10. const result = this._chain.then(task);
  11. this._chain = result.catch(() => {});
  12. return result;
  13. }
  14. }
  15. module.exports = {TaskQueue};