cleanup

Cleanup handling for domains.

npm install cleanup
2 downloads in the last day
6 downloads in the last week
18 downloads in the last month

Cleanup -- cleanup handlers for domains

npm install cleanup

var cleanup = require('cleanup')

var domain = cleanup(function (error) {
  doDatabaseCleaning(function (e, success) {
    if (error) process.exit(1)
    server.close()
  })
})

domain.enter()

var server = http.createServer(function (req, resp) {
  doDatabaseQuery(function (e, message) {
    if (e) throw e
    resp.statusCode = 200
    resp.end('ok')
  })
})

server.listen(8080, function () {
  writeManyThingsToDatabase(function (e, i) {
    if (e) throw e
    request('http://localhost:8080', function (e, resp, body) {
      if (e) throw e
      assert.equal(resp.statusCode, 200)

      domain.cleanup()
    })
  })
})
npm loves you