Skip to content

Commit

Permalink
fix(fromFetch): don't abort if fetch resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Apr 26, 2019
1 parent 2597e0d commit ed8d771
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/internal/observable/dom/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab
const controller = new AbortController();
const signal = controller.signal;
let outerSignalHandler: () => void;
let abortable = true;
let unsubscribed = false;

if (init) {
Expand All @@ -73,9 +74,11 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab
}

fetch(input, init).then(response => {
abortable = false;
subscriber.next(response);
subscriber.complete();
}).catch(err => {
abortable = false;
if (!unsubscribed) {
// Only forward the error if it wasn't an abort.
subscriber.error(err);
Expand All @@ -84,7 +87,9 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab

return () => {
unsubscribed = true;
controller.abort();
if (abortable) {
controller.abort();
}
};
});
}

0 comments on commit ed8d771

Please sign in to comment.