Skip to content

Commit

Permalink
Changed 'complete' event to 'end' in order to be consistent with the …
Browse files Browse the repository at this point in the history
…rest of NGN
  • Loading branch information
coreybutler committed Sep 21, 2020
1 parent 4a9e994 commit e05efb0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ngnjs/queue",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"description": "A lightweight NGN queue (taskrunner).",
"type": "module",
"main": "src/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class Item extends NGN.EventEmitter {
#done = () => {
clearTimeout(this.#timer)
this.#status = 'complete'
this.emit('complete', this)
this.emit('end', this)
this.emit('done')
INFO('QUEUE.TASK.DONE', `Finished processing ${this._dsc}.`)
}
Expand Down
8 changes: 4 additions & 4 deletions src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Queue extends EventEmitter {
moduleVersion: NGN.hiddenconstant('<#REPLACE_VERSION#>')
})

this.on('complete', () => this.reset())
this.on('end', () => this.reset())

// Add the cancel alias.
this.alias('cancel', this.abort)
Expand Down Expand Up @@ -251,7 +251,7 @@ export default class Queue extends EventEmitter {
// Immediately "complete" when the queue is empty.
if (this.#queue.size === 0) {
this._status = 'pending'
this.emit('complete')
this.emit('end')
return
}

Expand All @@ -266,7 +266,7 @@ export default class Queue extends EventEmitter {
}

if (!sequential) {
this.afterOnce('task.done', this.size, 'complete')
this.afterOnce('task.done', this.size, 'end')

// Run in parallel
// const TOKEN = Symbol('queue runner')
Expand All @@ -284,7 +284,7 @@ export default class Queue extends EventEmitter {
})
}

process.run(() => this.emit('complete'))
process.run(() => this.emit('end'))
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/01-sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('Sanity', t => {
}

const TaskRunner = new Queue()
t.ok(typeof TaskRunner === 'object', 'The plugin class is recognized.')
t.expect('object', typeof TaskRunner, 'The plugin class is recognized.')

// This functionality/test was removed so the NGN namespace does not need to be a Proxy
// t.ok(NGN.Queue !== undefined, 'The exported queue is available directly on the NGN namespace.')
Expand Down Expand Up @@ -98,9 +98,9 @@ test('NGN Queue parallel execution', t => {
})

let ended = false
tasks.on('complete', function () {
tasks.on('end', function () {
if (ended) {
t.fail("'complete' event fired more than once.")
t.fail("'end' event fired more than once.")
t.end()
return
}
Expand Down Expand Up @@ -135,7 +135,7 @@ test('NGN Queue Async execution', t => {
x.push('Task 3')
})

tasks.on('complete', function () {
tasks.on('end', function () {
t.ok(x.length === 3, 'Invalid result.' + x.toString())
t.end()
})
Expand Down Expand Up @@ -247,7 +247,7 @@ test('NGN Queue Simple linear execution', t => {
x.push(3)
})

tasks.on('complete', function () {
tasks.on('end', function () {
t.ok(x[0] === 1 && x[1] === 2 && x[2] === 3, 'Invalid result.' + x.toString())
t.end()
})
Expand Down Expand Up @@ -280,7 +280,7 @@ test('NGN Queue Asynchronous sequential execution', t => {

extra.skip()

tasks.on('complete', function () {
tasks.on('end', function () {
t.ok(x.length === 3, 'Appropriately skipped step.')
t.ok(x[0] === 1 && x[1] === 2 && x[2] === 3, 'Valid result: ' + x.toString())
t.end()
Expand Down Expand Up @@ -326,7 +326,7 @@ test('NGN Queue Abort Process', t => {

test('NGN Queue Process an empty queue.', t => {
const tasks = new Queue()
tasks.on('complete', function () {
tasks.on('end', function () {
t.pass('No error on empty task.')
tasks.reset()
t.end()
Expand Down

0 comments on commit e05efb0

Please sign in to comment.