Skip to content

Commit

Permalink
fix: handle rejections in main loop better
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
JackCuthbert committed Nov 18, 2019
1 parent c1b424c commit cbf3d12
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,20 @@ async function main () {
await setSlackStatus(status)
}

/** Passed to setInterval and does not kill the application on error */
const loop = () => main().catch(error => {
console.error(error)
})

validateConfig(config)
.then(main)
.then(() => {
setInterval(main, config.updateInterval * 60000)
})
.then(setInterval.bind(
null,
loop,
config.updateInterval * 60000)

This comment has been minimized.

Copy link
@JackCuthbert

JackCuthbert Nov 18, 2019

Author Owner

This syntax makes me sad, oops.

)
.catch(error => {
console.error(chalk.red(error.message))
console.error(error)
process.exit(1)
})

0 comments on commit cbf3d12

Please sign in to comment.