Socket
Socket
Sign inDemoInstall

avvio

Package Overview
Dependencies
Maintainers
2
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

avvio - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

26

boot.js

@@ -93,3 +93,4 @@ 'use strict'

}
this._closeQ = fastq(this, callWithCbOrNextTick, 1)
this._closeQ = fastq(this, closeWithCbOrNextTick, 1)
this._closeQ.pause()

@@ -99,2 +100,3 @@ this._closeQ.drain = () => {

}
this._thereIsCloseCb = false

@@ -196,2 +198,3 @@ // we init, because we need to emit "start" if no use is called

this._closeQ.push(cb)
this._thereIsCloseCb = true
}

@@ -225,2 +228,23 @@ process.nextTick(this._closeQ.resume.bind(this._closeQ))

function closeWithCbOrNextTick (func, cb, context) {
context = this._server
if (this._closeQ.length() === 0 && this._thereIsCloseCb) {
if (func.length === 0 || func.length === 1) {
func(this._error)
process.nextTick(cb)
} else if (func.length === 2) {
func(this._error, cb)
} else {
func(this._error, context, cb)
}
} else {
if (func.length === 0 || func.length === 1) {
func(context)
process.nextTick(cb)
} else {
func(context, cb)
}
}
}
module.exports = Boot

@@ -227,0 +251,0 @@ module.exports.express = function (app) {

2

package.json
{
"name": "avvio",
"version": "2.0.2",
"version": "2.0.3",
"description": "Asynchronous bootstrapping of Node applications",

@@ -5,0 +5,0 @@ "main": "boot.js",

@@ -322,3 +322,3 @@ # avvio

<a name="onClose"></a>
### app.onClose(func(error, [context], [done]))
### app.onClose(func([context], [done]))

@@ -328,5 +328,4 @@ Registers a new callback that will be fired once then `close` api is called.

The callback changes basing on the parameters your are giving:
1. If one parameter is given to the callback, that parameter will be the `error` object.
2. If two parameters are given to the callback, the first will be the `error` object, the second will be the `done` callback.
3. If three parameters are given to the callback, the first will be the `error` object, the second will be the `context` and the third the `done` callback.
1. If one parameter is given to the callback, that parameter will be the `context`.
2. If two parameters are given to the callback, the first will be the `context`, the second will be the `done` callback.

@@ -337,18 +336,11 @@ ```js

// onClose with one parameter
boot.onClose(function (err) {
if (err) throw err
boot.onClose(function (context) {
// ...
})
// onClose with two parameter
boot.onClose(function (err, done) {
if (err) throw err
boot.onClose(function (context, done) {
// ...
done()
})
// onClose with three parameters
boot.onClose(function (err, context, done) {
if (err) throw err
assert.equal(context, server)
done()
})
```

@@ -355,0 +347,0 @@

@@ -35,4 +35,4 @@ 'use strict'

app.use(function (server, opts, done) {
app.onClose((err, instance, done) => {
t.error(err)
app.onClose((instance, done) => {
t.ok('called')
t.equal(app, instance)

@@ -57,4 +57,4 @@ done()

app.use(function (server, opts, done) {
app.onClose((err, instance, done) => {
t.error(err)
app.onClose((instance, done) => {
t.ok('called')
done(new Error('some error'))

@@ -73,2 +73,28 @@ })

test('onClose should handle errors / 2', (t) => {
t.plan(4)
const app = boot()
app.onClose((instance, done) => {
t.ok('called')
done(new Error('some error'))
})
app.use(function (server, opts, done) {
app.onClose((instance, done) => {
t.ok('called')
done()
})
done()
})
app.on('start', () => {
app.close(err => {
t.is(err.message, 'some error')
t.pass('Closed in the correct order')
})
})
})
test('close arguments', (t) => {

@@ -80,4 +106,4 @@ t.plan(4)

app.use(function (server, opts, done) {
app.onClose((err, instance, done) => {
t.error(err)
app.onClose((instance, done) => {
t.ok('called')
done()

@@ -156,4 +182,4 @@ })

app.onClose((err, instance, done) => {
t.error(err)
app.onClose((instance, done) => {
t.ok('called')
done()

@@ -160,0 +186,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc