Skip to content

Commit db63659

Browse files
larrybothagodu
authored andcommitted
fix(sqs): fix unresolved promise blocking further serverless processes
fixes #171
1 parent 148d096 commit db63659

File tree

1 file changed

+14
-11
lines changed
  • packages/serverless-offline-sqs/src

1 file changed

+14
-11
lines changed

packages/serverless-offline-sqs/src/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ServerlessOfflineSQS {
4545
this.hooks = {
4646
'offline:start:init': this.start.bind(this),
4747
'offline:start:ready': this.ready.bind(this),
48-
'offline:start': this._startWithExplicitEnd.bind(this),
48+
'offline:start': this._startWithReady.bind(this),
4949
'offline:start:end': this.end.bind(this)
5050
};
5151
}
@@ -72,24 +72,27 @@ class ServerlessOfflineSQS {
7272
);
7373
}
7474

75-
async ready() {
75+
ready() {
7676
if (process.env.NODE_ENV !== 'test') {
77-
await this._listenForTermination();
77+
this._listenForTermination();
7878
}
7979
}
8080

81-
async _listenForTermination() {
82-
const command = await new Promise(resolve => {
83-
process.on('SIGINT', () => resolve('SIGINT')).on('SIGTERM', () => resolve('SIGTERM'));
84-
});
81+
_listenForTermination() {
82+
const signals = ['SIGINT', 'SIGTERM'];
83+
84+
signals.map(signal =>
85+
process.on(signal, async () => {
86+
this.serverless.cli.log(`Got ${signal} signal. Offline Halting...`);
8587

86-
this.serverless.cli.log(`Got ${command} signal. Offline Halting...`);
88+
await this.end();
89+
})
90+
);
8791
}
8892

89-
async _startWithExplicitEnd() {
93+
async _startWithReady() {
9094
await this.start();
91-
await this.ready();
92-
this.end();
95+
this.ready();
9396
}
9497

9598
async end(skipExit) {

0 commit comments

Comments
 (0)