1.0.0 • Published 7 years ago

toa-pm v1.0.0

Weekly downloads
22
License
-
Repository
github
Last release
7 years ago

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

  • app: Toa application.
  • handle: {Function|Object}, if omit handle, the default handle will be used:

    function defaultHandle(message) {
      if (message === 'shutdown') {
        this.server.close(() => process.exit(0))
      }
    }

    Default handle accept a 'shutdown' message to stop from accepting new connections and keeps existing connections. The server is finally closed and exit gracefully when all connections are ended. For example: pm2 gracefulReload app

License

The MIT License (MIT)

1.0.0

7 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

9 years ago

0.1.0

9 years ago