Skip to content

Commit

Permalink
Merge pull request joltup#130 from pexels/fix/scoped-cancel-task
Browse files Browse the repository at this point in the history
🐛 Fix Task Scoping for Fetch Cancellation
  • Loading branch information
RonRadtke authored Mar 25, 2022
2 parents 5e17a74 + 3c3fd48 commit 50ae139
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions polyfill/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ class ReactNativeBlobUtilFetchPolyfill {
// task.then is not, so we have to extend task.then with progress and
// cancel function
let progressHandler, uploadHandler, cancelHandler;
let scopedTask = null;
let statefulPromise = promise
.then((body) => {
let task = RNconfig(config)
.fetch(options.method, url, options.headers, body);
scopedTask = task;
if (progressHandler)
task.progress(progressHandler);
if (uploadHandler)
Expand All @@ -87,8 +89,8 @@ class ReactNativeBlobUtilFetchPolyfill {
};
statefulPromise.cancel = () => {
cancelHandler = true;
if (task.cancel)
task.cancel();
if (scopedTask && scopedTask.cancel)
scopedTask.cancel();
};

return statefulPromise;
Expand Down

0 comments on commit 50ae139

Please sign in to comment.