Home

Awesome

toa-pm

Process events manager for toa.

NPM version Build Status Downloads

toa

Example

Demo 1, with defaultHandle:

const Toa = require('toa')
const pm = require('toa-pm')

const app = new Toa()
app.use(function() {
  this.body = 'Hello world!'
})

app.listen(3000)
pm(app)

Demo 2:

const Toa = require('toa')
const pm = require('toa-pm')

const app = new Toa()
app.use(function() {
  this.body = 'Hello world!'
})

app.listen(3000)

pm(app, function(message) {
  // the context is `app`
  if (message === 'shutdown') {
    // do some thing....
  } else {
    // ...
  }
})

Demo 3:

const Toa = require('toa')
const pm = require('toa-pm')

const app = new Toa()
app.use(function() {
  this.body = 'Hello world!'
})

app.listen(3000)

pm(app, {
  message: function(message) {
    // the context is `app`
    if (message === 'shutdown') {
      // do some thing....
    } else {
      // ...
    }
  },
  beforeExit: function() {
    // do some thing.... when process emit `beforeExit` event
  }
})

Installation

npm install toa-pm

API

const pm = require('toa-pm')

pm(app[, handle])

It will add handle to process's message event, or add one more event-handle to process. ** Use it after app.listen **

License

The MIT License (MIT)