itinance/react-native-fs

Cancel all downloads

オープン

#297 opened on 2017/05/22

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C++ (1,012 件のフォーク)batch import
help wantedquestion

Repository metrics

Stars
 (5,043 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Hi everyone,

first of all, thank you all for providing and maintaining RNFS.

I am currently developing an app that allows users to download modules which consists of a lot of files (~300).

What I got so far (simplified version):

return await Promise.all(contents.map(async (file) => {
    await RNFS.downloadFile({
        fromUrl: basedir + '/' + file,
        toFile: moduleFolder + '/' + file,
        begin: (job) => {
            console.log('Begin job: ' + job.jobId);
        }
    })
    .promise.then((job) => {
        console.log('Job done: ' + job.jobId);
    })
    .catch((err) => {
        console.log(err);
    });
}))
.then(() => {
    console.log('Download complete.');
})
.catch((err) => {
    console.log(err);
});

Now, what I can't quite wrap my head around yet is how to implement a function that stops all pending downloads.

I tried cancelling each download with stopDownload(job.jobId) as soon as the download begins, but then the debugger starts throwing a lot of errors like the following:

https://cloud.githubusercontent.com/assets/17614778/21006568/b3e050c8-bd39-11e6-8ba1-c6fa51f5b1b4.png

Also, this approach somehow doesn't feel like the right way to handle the issue.

I also tried adding download promises recursively, and experimented with Bluebird and cancellable promises, but haven't succeeded yet.

Any help is greatly appreciated. Thank you!

コントリビューターガイド