diff --git a/package.json b/package.json index dcf571d..1b077ea 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/item.js b/src/item.js index da3442e..e85f310 100644 --- a/src/item.js +++ b/src/item.js @@ -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}.`) } diff --git a/src/runner.js b/src/runner.js index 0522eb9..5536264 100644 --- a/src/runner.js +++ b/src/runner.js @@ -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) @@ -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 } @@ -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') @@ -284,7 +284,7 @@ export default class Queue extends EventEmitter { }) } - process.run(() => this.emit('complete')) + process.run(() => this.emit('end')) } } diff --git a/tests/01-sanity.js b/tests/01-sanity.js index dc5960c..5f04f2b 100644 --- a/tests/01-sanity.js +++ b/tests/01-sanity.js @@ -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.') @@ -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 } @@ -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() }) @@ -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() }) @@ -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() @@ -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()