Skip to content

Commit

Permalink
Make sure we always start in a microtick (#189)
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Fixes: fastify/fastify#4125
  • Loading branch information
mcollina authored Jul 11, 2022
1 parent 392d84d commit 865a454
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Boot.prototype.ready = function (func) {
throw new AVV_ERR_CALLBACK_NOT_FN('ready', typeof func)
}
this._readyQ.push(func)
this.start()
queueMicrotask(this.start.bind(this))
return
}

Expand Down
22 changes: 22 additions & 0 deletions test/await-use.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,25 @@ test('await use - mix of same and future tick callbacks', async (t) => {
record += 'ready'
t.equal(record, 'plugin0|plugin1|plugin2|ready')
})

test('await use - fork the promise chain', { only: true }, (t) => {
t.plan(3)
const app = {}
boot(app, { autostart: false })

async function setup () {
let set = false
await app.use(async function plugin0 () {
t.pass('plugin0 init')
await sleep(500)
set = true
})
t.equal(set, true)
}
setup()

app.ready((err, done) => {
t.error(err)
done()
})
})
2 changes: 1 addition & 1 deletion test/chainable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test('chainable automatically binded', (t) => {
expose[key] = 'muahah'

boot(app, {
expose: expose
expose
})

t.end()
Expand Down

0 comments on commit 865a454

Please sign in to comment.