-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1137 from interval/begin-shutdown
Add async `safelyClose` method to close after transactions complete
- Loading branch information
Showing
5 changed files
with
118 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Interval from '../../index' | ||
import { sleep } from '../utils/helpers' | ||
|
||
const interval = new Interval({ | ||
apiKey: 'live_N47qd1BrOMApNPmVd0BiDZQRLkocfdJKzvt8W6JT5ICemrAN', | ||
logLevel: 'debug', | ||
endpoint: 'ws://localhost:3000/websocket', | ||
routes: { | ||
wait_a_while: async (io, ctx) => { | ||
await ctx.loading.start('Waiting...') | ||
await sleep(5000) | ||
return 'Done!' | ||
}, | ||
}, | ||
}) | ||
|
||
interval.listen() | ||
|
||
process.on('SIGINT', () => { | ||
interval | ||
.safelyClose() | ||
.then(() => { | ||
console.log('Shut down!') | ||
process.exit(0) | ||
}) | ||
.catch(err => { | ||
console.error( | ||
'Failed shutting down gracefully, forcibly closing connection' | ||
) | ||
interval.immediatelyClose() | ||
process.exit(0) | ||
}) | ||
}) |
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