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 5.6.0 to 5.7.0

14

boot.js

@@ -318,8 +318,16 @@ 'use strict'

if (func.length === 0 || func.length === 1) {
var promise
if (isOnCloseHandler) {
func(context)
promise = func(context)
} else {
func(this._error)
promise = func(this._error)
}
process.nextTick(cb)
if (promise && typeof promise.then === 'function') {
debug('resolving close/onClose promise')
promise.then(
() => process.nextTick(cb),
(e) => process.nextTick(cb, e))
} else {
process.nextTick(cb)
}
} else if (func.length === 2) {

@@ -326,0 +334,0 @@ if (isOnCloseHandler) {

{
"name": "avvio",
"version": "5.6.0",
"version": "5.7.0",
"description": "Asynchronous bootstrapping of Node applications",

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

@@ -382,3 +382,4 @@ # avvio

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 top level `context` unless you have specified both server and override, in that case the `context` will be what the override returns, the second will be the `done` callback.
2. If zero or one parameter is given, the callback may return a promise
3. If two parameters are given to the callback, the first will be the top level `context` unless you have specified both server and override, in that case the `context` will be what the override returns, the second will be the `done` callback.

@@ -394,2 +395,16 @@ ```js

// onClose with one parameter, returning a promise
app.onClose(function (context) {
return new Promise((resolve, reject) => {
// ...
})
})
// async onClose with one parameter
app.onClose(async function (context) {
// ...
await ...
})
// onClose with two parameter

@@ -402,2 +417,4 @@ app.onClose(function (context, done) {

If the callback returns a promise, the next onClose callback and the close callback won't run until the promise is either resolved or rejected.
`done` must be called only once.

@@ -404,0 +421,0 @@ Returns the instance on which `onClose` is called, to support a chainable API.

@@ -407,1 +407,31 @@ 'use strict'

})
test('close with async onClose handlers', (t) => {
t.plan(5)
const app = boot()
var order = [1, 2, 3, 4]
app.onClose(() => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.is(order.shift(), 3)
})
})
app.onClose(() => {
t.is(order.shift(), 2)
})
app.onClose((instance) => {
return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
t.is(order.shift(), 1)
})
})
app.on('start', () => {
app.close(() => {
t.is(order.shift(), 4)
t.pass('Closed in the correct order')
})
})
})
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