Skip to content
This repository was archived by the owner on Jul 30, 2018. It is now read-only.

Conversation

nicknisi
Copy link
Member

@nicknisi nicknisi commented May 31, 2018

Type: feature

The following has been addressed in the PR:

Description:

Note: This PR is dependent on dojo/shim#143.

Resolves #390

add support for a signal: AbortSignal property in the request options. When provided, the request can be aborted by calling the AbortController#abort method, similar to the fetch API. When a request is aborted, the Promise is rejected with an AbortError, if possible.

add support for a signal: AbortSignal property in the request options
When provided, the request can be aborted by calling the
AbortController#abort method, similar to the fetch API
@nicknisi nicknisi changed the title add support for signal request option fixes #390 add support for signal request option May 31, 2018
When abort is triggered, update the request Task to reject with a
AbortError instead of canceling the Task. Tasks can still be canceled
with the .cancel method.
abortError = new Error('Aborted');
abortError.name = 'AbortError';
}
reject(new DOMException('Aborted', 'AbortError'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you should use abortError here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Thanks!

timeoutReject = reject;

if (options.signal) {
options.signal.addEventListener('abort', () => {
Copy link

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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 abort events will have no effect on a fulfilled Task.

Copy link

Choose a reason for hiding this comment

The 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.

}

if (options.signal) {
options.signal.addEventListener('abort', () => {
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants