Skip to content

Commit

Permalink
Revert "fix: delay plugin promise resolution until next tick (#173)"
Browse files Browse the repository at this point in the history
This reverts commit 15c4cd3.
  • Loading branch information
mcollina committed Feb 25, 2022
1 parent f9d8126 commit aee639e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 65 deletions.
20 changes: 9 additions & 11 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,16 @@ Plugin.prototype.loadedSoFar = function () {
this._error = err
this.q.pause()

process.nextTick(() => {
if (err) {
debug('rejecting promise', this.name, err)
this._promise.reject(err)
} else {
debug('resolving promise', this.name)
this._promise.resolve()
}
this._promise = null
if (err) {
debug('rejecting promise', this.name, err)
this._promise.reject(err)
} else {
debug('resolving promise', this.name)
this._promise.resolve()
}
this._promise = null

process.nextTick(cb, err)
})
process.nextTick(cb, err)
})
this.q.resume()
}
Expand Down
54 changes: 1 addition & 53 deletions test/await-after.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const { test } = require('tap')
const boot = require('..')
const { promisify } = require('util')
const sleep = promisify(setTimeout)
const fs = require('fs').promises
const path = require('path')

test('await after - nested plugins with same tick callbacks', async (t) => {
const app = {}
Expand Down Expand Up @@ -275,7 +273,7 @@ test('await after complex scenario', async (t) => {
t.notOk(fourthLoaded, 'fourth is not loaded')
app.use(second)
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
app.use(third)
Expand Down Expand Up @@ -308,56 +306,6 @@ test('await after complex scenario', async (t) => {
}
})

test('without autostart and sync/async plugin mix', async (t) => {
const app = {}
boot(app, { autostart: false })
t.plan(11)

let firstLoaded = false
let secondLoaded = false
let thirdLoaded = false

app.use(first)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')

const contents = await fs.readFile(path.join(__dirname, 'fixtures', 'dummy.txt'), 'utf-8')
t.equal(contents, 'hello, world!')

app.use(second)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')

await sleep(10)

app.use(third)
await app.after()
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')

await app.ready()

async function first () {
firstLoaded = true
}

async function second () {
const contents = await fs.readFile(path.join(__dirname, 'fixtures', 'dummy.txt'), 'utf-8')
t.equal(contents, 'hello, world!')
secondLoaded = true
}

async function third (app) {
await sleep(10)
thirdLoaded = true
}
})

test('without autostart', async (t) => {
const app = {}
boot(app, { autostart: false })
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/dummy.txt

This file was deleted.

0 comments on commit aee639e

Please sign in to comment.