Comparing version 4.0.0 to 4.0.1
28
boot.js
@@ -110,4 +110,5 @@ 'use strict' | ||
this._readyQ.drain = () => { | ||
this.booted = true | ||
this.emit('start') | ||
// nooping this, we want to emit start only once | ||
this._readyQ.drain = noop | ||
} | ||
@@ -119,2 +120,4 @@ | ||
this.emit('close') | ||
// nooping this, we want to emit start only once | ||
this._closeQ.drain = noop | ||
} | ||
@@ -139,2 +142,3 @@ this._thereIsCloseCb = false | ||
} else { | ||
this.booted = true | ||
this._readyQ.resume() | ||
@@ -228,3 +232,4 @@ } | ||
Boot.prototype.close = function (func) { | ||
this._error = null | ||
var promise | ||
if (func) { | ||
@@ -234,6 +239,21 @@ if (typeof func !== 'function') { | ||
} | ||
} else { | ||
promise = new Promise(function (resolve, reject) { | ||
func = function (err) { | ||
if (err) { | ||
return reject(err) | ||
} | ||
resolve() | ||
} | ||
}) | ||
} | ||
this.ready(() => { | ||
this._error = null | ||
this._closeQ.push(func) | ||
this._thereIsCloseCb = true | ||
} | ||
process.nextTick(this._closeQ.resume.bind(this._closeQ)) | ||
process.nextTick(this._closeQ.resume.bind(this._closeQ)) | ||
}) | ||
return promise | ||
} | ||
@@ -240,0 +260,0 @@ |
{ | ||
"name": "avvio", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
@@ -5,0 +5,0 @@ "main": "boot.js", |
@@ -258,1 +258,24 @@ 'use strict' | ||
}) | ||
test('booted should be set before ready', (t) => { | ||
t.plan(2) | ||
const app = boot() | ||
app.ready(function (err) { | ||
t.error(err) | ||
t.equal(app.booted, true) | ||
}) | ||
}) | ||
test('throws correctly if registering after ready', (t) => { | ||
t.plan(1) | ||
const app = boot() | ||
app.ready(function () { | ||
t.throws(() => { | ||
app.use((a, b, done) => done()) | ||
}, 'root plugin has already booted') | ||
}) | ||
}) |
@@ -344,1 +344,28 @@ 'use strict' | ||
}) | ||
test('close should trigger ready()', (t) => { | ||
t.plan(2) | ||
const app = boot(null, { | ||
autostart: false | ||
}) | ||
app.on('start', () => { | ||
// this will be emitted after the | ||
// callback in close() is fired | ||
t.pass('started') | ||
}) | ||
app.close(() => { | ||
t.pass('closed') | ||
}) | ||
}) | ||
test('close without a cb returns a promise', (t) => { | ||
t.plan(1) | ||
const app = boot() | ||
app.close().then(() => { | ||
t.pass('promise resolves') | ||
}) | ||
}) |
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
63282
2001