Comparing version 5.4.1 to 5.4.2
30
boot.js
@@ -99,2 +99,3 @@ 'use strict' | ||
this._error = null | ||
this._isOnCloseHandlerKey = Symbol('isOnCloseHandler') | ||
@@ -125,3 +126,2 @@ this.setMaxListeners(0) | ||
} | ||
this._thereIsCloseCb = false | ||
@@ -215,2 +215,5 @@ this._doStart = null | ||
Boot.prototype.onClose = function (func) { | ||
// this is used to distinguish between onClose and close handlers | ||
// because they share the same queue but must be called with different signatures | ||
func[this._isOnCloseHandlerKey] = true | ||
this._closeQ.unshift(func, callback.bind(this)) | ||
@@ -246,3 +249,2 @@ | ||
this._closeQ.push(func) | ||
this._thereIsCloseCb = true | ||
process.nextTick(this._closeQ.resume.bind(this._closeQ)) | ||
@@ -312,17 +314,21 @@ }) | ||
context = this._server | ||
if (this._closeQ.length() === 0 && this._thereIsCloseCb) { | ||
if (func.length === 0 || func.length === 1) { | ||
var isOnCloseHandler = func[this._isOnCloseHandlerKey] | ||
if (func.length === 0 || func.length === 1) { | ||
if (isOnCloseHandler) { | ||
func(context) | ||
} else { | ||
func(this._error) | ||
process.nextTick(cb) | ||
} else if (func.length === 2) { | ||
} | ||
process.nextTick(cb) | ||
} else if (func.length === 2) { | ||
if (isOnCloseHandler) { | ||
func(context, cb) | ||
} else { | ||
func(this._error, cb) | ||
} else { | ||
func(this._error, context, cb) | ||
} | ||
} else { | ||
if (func.length === 0 || func.length === 1) { | ||
func(context) | ||
process.nextTick(cb) | ||
if (isOnCloseHandler) { | ||
func(context, cb) | ||
} else { | ||
func(context, cb) | ||
func(this._error, context, cb) | ||
} | ||
@@ -329,0 +335,0 @@ } |
@@ -7,3 +7,7 @@ 'use strict' | ||
.use(first, { hello: 'world' }) | ||
.after((cb) => { | ||
.after((err, cb) => { | ||
if (err) { | ||
console.log('something bad happened') | ||
console.log(err) | ||
} | ||
console.log('after first and second') | ||
@@ -26,3 +30,4 @@ cb() | ||
console.log('first loaded', opts) | ||
instance.use(second, cb) | ||
instance.use(second) | ||
cb() | ||
} | ||
@@ -29,0 +34,0 @@ |
{ | ||
"name": "avvio", | ||
"version": "5.4.1", | ||
"version": "5.4.2", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
@@ -33,6 +33,6 @@ "main": "boot.js", | ||
"devDependencies": { | ||
"express": "^4.16.2", | ||
"express": "^4.16.3", | ||
"pre-commit": "^1.2.2", | ||
"standard": "^10.0.3", | ||
"tap": "^11.0.1", | ||
"standard": "^11.0.0", | ||
"tap": "^11.1.3", | ||
"then-sleep": "^1.0.1" | ||
@@ -39,0 +39,0 @@ }, |
@@ -48,5 +48,5 @@ 'use strict' | ||
debug('resolving promise', name) | ||
promise | ||
.then(() => process.nextTick(done), | ||
(e) => process.nextTick(done, e)) | ||
promise.then( | ||
() => process.nextTick(done), | ||
(e) => process.nextTick(done, e)) | ||
} | ||
@@ -53,0 +53,0 @@ |
@@ -408,3 +408,3 @@ # avvio | ||
Starts the shotdown procedure, the callback is called once all the registered callbacks with `onClose` has been executed. | ||
Starts the shutdown procedure, the callback is called once all the registered callbacks with `onClose` has been executed. | ||
@@ -411,0 +411,0 @@ The callback changes basing on the parameters your are giving: |
@@ -13,8 +13,9 @@ 'use strict' | ||
app.use(first) | ||
.after(() => { | ||
t.ok(firstLoaded, 'first is loaded') | ||
t.ok(secondLoaded, 'second is loaded') | ||
t.pass('booted') | ||
}) | ||
app | ||
.use(first) | ||
.after(() => { | ||
t.ok(firstLoaded, 'first is loaded') | ||
t.ok(secondLoaded, 'second is loaded') | ||
t.pass('booted') | ||
}) | ||
@@ -21,0 +22,0 @@ function first (s, opts, done) { |
@@ -189,2 +189,28 @@ 'use strict' | ||
test('#54 close handlers should receive same parameters when queue is not empty', (t) => { | ||
t.plan(6) | ||
const context = { test: true } | ||
const app = boot(context) | ||
app.use(function (server, opts, done) { | ||
done() | ||
}) | ||
app.on('start', () => { | ||
app.close((err, done) => { | ||
t.is(err, null) | ||
t.pass('Closed in the correct order') | ||
setImmediate(done) | ||
}) | ||
app.close(err => { | ||
t.is(err, null) | ||
t.pass('Closed in the correct order') | ||
}) | ||
app.close(err => { | ||
t.is(err, null) | ||
t.pass('Closed in the correct order') | ||
}) | ||
}) | ||
}) | ||
test('onClose should handle errors / 2', (t) => { | ||
@@ -191,0 +217,0 @@ t.plan(4) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70863
2300