Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demonstrate async cleanup in graceful shutdowns
- Loading branch information
1 parent
83126e5
commit a771229
Showing
4 changed files
with
29 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
'use strict'; | ||
|
||
const throng = require('../../lib/throng'); | ||
const throng = require('../../lib/throng') | ||
|
||
throng(3, (id, disconnect) => { | ||
let exited = false | ||
|
||
console.log('worker'); | ||
|
||
console.log('worker') | ||
process.on('SIGTERM', exit) | ||
process.on('SIGINT', exit) | ||
|
||
async function exit() { | ||
if (exited) return | ||
exited = true | ||
|
||
await new Promise(r => setTimeout(r, 100)) // simulate async cleanup | ||
console.log('exiting') | ||
disconnect() | ||
} | ||
}); | ||
}) |