-
Notifications
You must be signed in to change notification settings - Fork 58
add support for signal request option #399
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,19 @@ export default function xhr(url: string, options: XhrRequestOptions = {}): Uploa | |
const task = <UploadObservableTask<XhrResponse>>new Task<XhrResponse>((resolve, reject) => { | ||
timeoutReject = reject; | ||
|
||
if (options.signal) { | ||
options.signal.addEventListener('abort', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when the request is fulfilled, the event listener should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ycabon I'm not sure there's a good place in the code to remove this event listener. Also, I'm not sure it's necessary as subsequent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My concern was more for cases where the signal is reused for multiple calls, would the Task be kept in memory until the signal and controller are GCed. |
||
let abortError: Error; | ||
try { | ||
abortError = new DOMException('Aborted', 'AbortError'); | ||
} catch { | ||
abortError = new Error('Aborted'); | ||
abortError.name = 'AbortError'; | ||
} | ||
reject(abortError); | ||
}); | ||
} | ||
|
||
request.onreadystatechange = function() { | ||
if (isAborted) { | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when the request is fulfilled, the event listener should be removed.