Comparing version 5.0.1 to 5.1.0
17
boot.js
@@ -276,2 +276,3 @@ 'use strict' | ||
var err = this._error | ||
var res | ||
@@ -282,7 +283,15 @@ // with this the error will appear just in the next after/ready callback | ||
this._error = err | ||
func() | ||
process.nextTick(cb) | ||
res = func() | ||
if (res && typeof res.then === 'function') { | ||
res.then(() => process.nextTick(cb), (e) => process.nextTick(cb, e)) | ||
} else { | ||
process.nextTick(cb) | ||
} | ||
} else if (func.length === 1) { | ||
func(err) | ||
process.nextTick(cb) | ||
res = func(err) | ||
if (res && typeof res.then === 'function') { | ||
res.then(() => process.nextTick(cb), (e) => process.nextTick(cb, e)) | ||
} else { | ||
process.nextTick(cb) | ||
} | ||
} else if (func.length === 2) { | ||
@@ -289,0 +298,0 @@ func(err, cb) |
{ | ||
"name": "avvio", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
"main": "boot.js", | ||
"scripts": { | ||
"test": "standard && tap test/*test.js" | ||
"test": "standard && tap -j4 test/*test.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "precommit": "test", |
@@ -35,3 +35,5 @@ 'use strict' | ||
debug('resolving promise', name) | ||
promise.then(() => done()).catch(done) | ||
promise | ||
.then(() => process.nextTick(done), | ||
(e) => process.nextTick(done, e)) | ||
} | ||
@@ -38,0 +40,0 @@ |
@@ -216,2 +216,15 @@ # avvio | ||
}) | ||
// async after with one parameter | ||
app.after(async function (err) { | ||
await sleep(10) | ||
if (err) { | ||
throw err | ||
} | ||
}) | ||
// async after with no parameter | ||
app.after(async function () { | ||
await sleep(10) | ||
}) | ||
``` | ||
@@ -218,0 +231,0 @@ |
@@ -138,1 +138,46 @@ 'use strict' | ||
}) | ||
test('after', async (t) => { | ||
t.plan(15) | ||
const app = boot() | ||
let firstLoaded = false | ||
let secondLoaded = false | ||
let thirdLoaded = false | ||
app.use(first) | ||
async function first (s, opts) { | ||
t.notOk(firstLoaded, 'first is not loaded') | ||
t.notOk(secondLoaded, 'second is not loaded') | ||
t.notOk(thirdLoaded, 'third is not loaded') | ||
firstLoaded = true | ||
s.after(second) | ||
s.after(third) | ||
} | ||
async function second (err) { | ||
t.error(err) | ||
t.ok(firstLoaded, 'first is loaded') | ||
t.notOk(secondLoaded, 'second is not loaded') | ||
t.notOk(thirdLoaded, 'third is not loaded') | ||
await sleep(10) | ||
secondLoaded = true | ||
} | ||
async function third () { | ||
t.ok(firstLoaded, 'first is loaded') | ||
t.ok(secondLoaded, 'second is loaded') | ||
t.notOk(thirdLoaded, 'third is not loaded') | ||
await sleep(10) | ||
thirdLoaded = true | ||
} | ||
const readyContext = await app.ready() | ||
t.equal(app, readyContext) | ||
t.ok(firstLoaded, 'first is loaded') | ||
t.ok(secondLoaded, 'second is loaded') | ||
t.ok(thirdLoaded, 'third is loaded') | ||
t.pass('booted') | ||
}) |
Sorry, the diff of this file is not supported yet
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
63932
18
2012
443