Cleanup handling for domains.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md Initial commit Apr 5, 2013
index.js Always run on process exit, no matter what. Jun 15, 2013
package.json 0.3.1 Jun 15, 2013
test.js Enter domain automatically. May 2, 2013

README.md

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()
    })
  })
})