question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with canceling the request

See original GitHub issue

Specs: “react-native”: “0.55.4”, “rn-fetch-blob”: “0.10.12”,

Hello guys 😃

So I have a problem with canceling request. I’m trying to download some huge apk file (more than 400 MB) and I want to give user ability to cancel the download process.

So I’m creating the request in this way:

let request = RNFetchBlob.config({
             path: apkPath,
             fileCache: true
        }).fetch('GET', app.apkDownloadUrl)
           .then((res) => {[...]});

Then, when I call:

request.cancel();

There is error that says that “cancel” is not a function. What I’m doing wrong? 😃

BTW: Beside this issue, great library!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

6reactions
HasanAlyazidicommented, Feb 6, 2019

I managed to solve it with this workaround

    ...
    this.isCancelled = false; // <-- step 1 (needed if you want to retry downloading)

    this.task = config(options).fetch('GET', url);
    
    this.task.progress((received, total) => {
        let progress_value = received / total;
        this.setState({ progress_value });
    });

    this.task.then((res) => {
        if (this.isCancelled) return;  // <-- step 2

        // save to db/redux, etc...
    })
    .catch(err => console.log(err))
    ...

    _cancelDownload() {
        this.isCancelled = true; // <-- step 3

        this.task.cancel((err, taskId) => {
            // Handle cancelling
        });
    }
4reactions
ithustlecommented, Nov 29, 2018

I have an issue maybe is a bug, I don’t know. When I request a cancel the promise of success is triggered.

this.task = config(options).fetch('GET', url);
            this.task.progress((received, total) => {
                let progress_value = received / total;
                this.setState({ progress_value });
            });
            this.task.then((res) => {
                // Success handle - When I call _cancelDownload() this promise is triggered
                }).catch(err => console.log(err))  
            });
        }
    }

    _cancelDownload() {
        
        this.task.cancel((err, taskId) => {
            // Handle cancl
        });
        
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Respond to a Cancellation Requests + Email Templates
Handle cancellation requests better with these 10 sample emails. Templates that you can use to reply to cancellation emails.
Read more >
Request Cancellation - YouTube
There's a catch, though: although the client times out and displays an error, it doesn't actually cancel the request, so the application ...
Read more >
What is the Correct HTTP Status Code for a Cancelled Request
There's no ability within HTTP for a client to cancel a request. So it's not surprising that no code is defined for the...
Read more >
Canceling Requests - Redux Resource
Canceling requests prevents race conditions. A race condition occurs when you have two requests in flight at the same time, but your code...
Read more >
Request Cancellation - James Shore
This turns out to be a design problem. Although cancelling requests is easy to do in Node.js—you just call request.destroy() on the Node...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found