Skip to content

Commit

Permalink
can we shim the eventListeners?
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Aug 3, 2022
1 parent 91cdf0e commit 1b3f8bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
if (typeof AbortController === 'undefined') {
module.exports = {
AbortController: class AbortController {
signal = { aborted: false, addEventListener () {}, removeEventListener () {} }
#eventListener = new Set()
signal = {
aborted: false,
addEventListener: (_, listener) => {
this.#eventListener.add(listener)
},
removeEventListener: (_, listener) => {
this.#eventListener.delete(listener)
}
}

abort () {
this.signal.aborted = true
this.#eventListener.forEach(listener => listener())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-runner-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ if (process.argv[2] === 'child') {
assert.strictEqual(child.signal, null)

runAndKill(fixtures.path('test-runner', 'never_ending_sync.js')).then(common.mustCall())
runAndKill(fixtures.path('test-runner', 'never_ending_async.js')).then(typeof AbortSignal === 'undefined' ? undefined : common.mustCall())
runAndKill(fixtures.path('test-runner', 'never_ending_async.js')).then(common.mustCall())
}

0 comments on commit 1b3f8bb

Please sign in to comment.