Skip to content

Commit

Permalink
refactor: remove unhandledRejection listener
Browse files Browse the repository at this point in the history
implement it in egg
  • Loading branch information
popomore committed Aug 10, 2016
1 parent 3de0380 commit 6f91c5b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 26 deletions.
17 changes: 0 additions & 17 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ class EggCore extends KoaApplication {
});

this._initReady();

// 记录未处理的 promise reject
// 每个进程调用一次即可
this._unhandledRejectionHandler = this._unhandledRejectionHandler.bind(this);
process.on('unhandledRejection', this._unhandledRejectionHandler);
}

get type() {
Expand Down Expand Up @@ -122,7 +117,6 @@ class EggCore extends KoaApplication {
close() {
this.emit('close');
this.removeAllListeners();
process.removeListener('unhandledRejection', this._unhandledRejectionHandler);
}

/**
Expand Down Expand Up @@ -157,17 +151,6 @@ class EggCore extends KoaApplication {
this.console.warn('[egg:core:ready_timeout] 10 seconds later %s was still unable to finish.', id);
});
}

_unhandledRejectionHandler(err) {
if (!(err instanceof Error)) {
err = new Error(String(err));
}
if (err.name === 'Error') {
err.name = 'unhandledRejectionError';
}
this.coreLogger.error(err);
}

}

module.exports = EggCore;
9 changes: 0 additions & 9 deletions test/egg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,6 @@ describe('test/egg.test.js', () => {
let app;
afterEach(() => app.close());

it('should close all listeners', () => {
app = utils.createApp('close');
process.listeners('unhandledRejection')
.indexOf(app._unhandledRejectionHandler).should.not.equal(-1);
app.close();
process.listeners('unhandledRejection')
.indexOf(app._unhandledRejectionHandler).should.equal(-1);
});

it('should emit close event before exit', () => {
app = utils.createApp('close');
let called = false;
Expand Down

0 comments on commit 6f91c5b

Please sign in to comment.