Skip to content

Commit

Permalink
refactor: simplify signal handling (#3362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored Jun 23, 2024
1 parent 0455e06 commit 3f4ef9a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ class RequestHandler extends AsyncResource {
} else if (this.abort) {
this.abort(this.reason)
}

if (this.removeAbortListener) {
this.res?.off('close', this.removeAbortListener)
this.removeAbortListener()
this.removeAbortListener = null
}
})
}
}
Expand Down Expand Up @@ -127,6 +121,7 @@ class RequestHandler extends AsyncResource {

if (this.removeAbortListener) {
res.on('close', this.removeAbortListener)
this.removeAbortListener = null
}

this.callback = null
Expand Down Expand Up @@ -183,7 +178,6 @@ class RequestHandler extends AsyncResource {
}

if (this.removeAbortListener) {
res?.off('close', this.removeAbortListener)
this.removeAbortListener()
this.removeAbortListener = null
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ function addAbortListener (signal, listener) {
signal.addEventListener('abort', listener, { once: true })
return () => signal.removeEventListener('abort', listener)
}
signal.addListener('abort', listener)
signal.once('abort', listener)
return () => signal.removeListener('abort', listener)
}

Expand Down

0 comments on commit 3f4ef9a

Please # to comment.