Skip to content

Commit 50ae139

Browse files
authored
Merge pull request #130 from pexels/fix/scoped-cancel-task
🐛 Fix Task Scoping for Fetch Cancellation
2 parents 5e17a74 + 3c3fd48 commit 50ae139

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

polyfill/Fetch.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ class ReactNativeBlobUtilFetchPolyfill {
5959
// task.then is not, so we have to extend task.then with progress and
6060
// cancel function
6161
let progressHandler, uploadHandler, cancelHandler;
62+
let scopedTask = null;
6263
let statefulPromise = promise
6364
.then((body) => {
6465
let task = RNconfig(config)
6566
.fetch(options.method, url, options.headers, body);
67+
scopedTask = task;
6668
if (progressHandler)
6769
task.progress(progressHandler);
6870
if (uploadHandler)
@@ -87,8 +89,8 @@ class ReactNativeBlobUtilFetchPolyfill {
8789
};
8890
statefulPromise.cancel = () => {
8991
cancelHandler = true;
90-
if (task.cancel)
91-
task.cancel();
92+
if (scopedTask && scopedTask.cancel)
93+
scopedTask.cancel();
9294
};
9395

9496
return statefulPromise;

0 commit comments

Comments
 (0)