Skip to content

Commit

Permalink
Fixed an issue where the cancel API isn't working
Browse files Browse the repository at this point in the history
  • Loading branch information
nluzzato committed Oct 5, 2020
1 parent a12ed50 commit f979791
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions polyfill/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ class RNFetchBlobFetchPolyfill {
// 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 = RNFetchBlob.config(config)
.fetch(options.method, url, options.headers, body)
.fetch(options.method, url, options.headers, body)
scopedTask = task
if(progressHandler)
task.progress(progressHandler)
if(uploadHandler)
Expand All @@ -87,12 +91,11 @@ class RNFetchBlobFetchPolyfill {
}
statefulPromise.cancel = () => {
cancelHandler = true
if(task.cancel)
task.cancel()
if(scopedTask.cancel)
scopedTask.cancel()
}

return statefulPromise

}
}

Expand Down

0 comments on commit f979791

Please sign in to comment.