Skip to content

LuKks/terminable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terminable

Handle resources for graceful exit

const Terminable = require('terminable')

const terminable = new Terminable()

const timeoutId = setTimeout(function () {
  terminable.delete(timeoutId)
  console.log('long running task')
}, 5000)

const state = terminable.add(timeoutId, function () {
  clearTimeout(timeoutId)
  setTimeout(() => console.log('clean up async'), 500)
})

process.once('SIGINT', function () {
  state.cleanup()
})

console.log('Press CTRL+C to skip 5s timeout')

Install

npm i terminable

License

Code released under the MIT License.

Releases

No releases published

Packages

No packages published