Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): Deregister all events to the queue after batch #20798

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/gatsby/src/query/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const createDevelopQueue = getRunner => {
* Returns a promise that pushes jobs onto queue and resolves onces
* they're all finished processing (or rejects if one or more jobs
* fail)
* Note: queue is reused in develop so make sure to thoroughly cleanup hooks
*/
const processBatch = async (queue, jobs, activity) => {
let numJobs = jobs.length
Expand All @@ -97,11 +98,25 @@ const processBatch = async (queue, jobs, activity) => {
queue.on(`task_finish`, () => activity.tick())
}

const gc = () => {
queue.removeAllListeners(`task_failed`)
queue.removeAllListeners(`drain`)
queue.removeAllListeners(`task_finish`)
pvdz marked this conversation as resolved.
Show resolved Hide resolved
queue = null
}

queue
// Note: the first arg is the path, the second the error
.once(`task_failed`, (...err) => reject(err))
// Note: `drain` fires when all tasks _finish_, `empty` fires when queue is empty (but tasks are still running)
.once(`drain`, resolve)
.on(`task_failed`, (...err) => {
gc()
reject(err)
})
// Note: `drain` fires when all tasks _finish_
// `empty` fires when queue is empty (but tasks are still running)
.on(`drain`, () => {
gc()
resolve()
})

jobs.forEach(job => queue.push(job))
})
Expand Down