Skip to content

Commit

Permalink
Create an errors listener to reject the promise. (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Apr 3, 2020
1 parent 526377b commit fcd3825
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ class Generator extends EventEmitter {
// Ensure we emit the error event outside the promise context so it won't be
// swallowed when there's no listeners.
setImmediate(() => {
self.emit('error', err);
reject(err);
self.emit('error', err);
});
});
},
Expand Down Expand Up @@ -703,6 +703,9 @@ class Generator extends EventEmitter {
this.debug('Generator is starting');
this.emit('run');

// Add an error listener to reject the promise
this.on('error', reject);

const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(this));
const validMethods = methods.filter(methodIsValid);
if (!validMethods.length) {
Expand All @@ -726,7 +729,7 @@ class Generator extends EventEmitter {
const item = property.value ? property.value : property.get.call(self);

const priority = self._queues[name];
let taskOptions = { ...priority, reject };
let taskOptions = { ...priority };

// Name points to a function; run it!
if (typeof item === 'function') {
Expand Down

0 comments on commit fcd3825

Please sign in to comment.