Skip to content

Commit

Permalink
Fixed code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-van committed Oct 18, 2021
1 parent 16b2d29 commit bcb2098
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Queue.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Queue {
* @param {*} CancelledErrorClass ignore
* @returns {*} ignore
*/
_execCancellableInternal (fct, priority = 0, CancelledErrorClass = CancelledError) {
_execCancellableInternal (fct, priority, CancelledErrorClass = CancelledError) {
assert(typeof fct === 'function', 'fct must be a function')
assert(typeof priority === 'number', 'priority must be a number')
const deferred = new Deferred()
Expand All @@ -159,13 +159,10 @@ class Queue {
} else {
task.state = 'cancelled'
const filtered = this._iqueue.filter((v) => v !== task)
if (filtered.length < this._iqueue.length) {
this._iqueue = filtered
deferred.reject(new task.CancelledErrorClass())
return true
} else {
return false
}
assert(filtered.length < this._iqueue.length)
this._iqueue = filtered
deferred.reject(new task.CancelledErrorClass())
return true
}
}]
}
Expand Down
16 changes: 16 additions & 0 deletions src/Queue.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,19 @@ test('Queue custom error class', async () => {
}
expect(passed).toBe(false)
})

test('Queue cancel just scheduled', async () => {
let passed = false
const queue = new Queue(1)
const [p, cancel] = queue.execCancellable(() => {
passed = true
})
expect(cancel()).toBe(true)
try {
await p
expect(true).toBe(false)
} catch (e) {
expect(e instanceof CancelledError).toBe(true)
}
expect(passed).toBe(false)
})

0 comments on commit bcb2098

Please sign in to comment.