0

Hello i use mergemap from rxjs. I use array of object.

const list = [{name:'test',url:'https.....'}.....]
const source = from(list)
.pipe(mergeMap(getFile, null, 4))
.subscribe(saveDB);

In my getFile function I do downlaod file using axios to blob and in subscribe save. Now Lets say i wan to cancel all process for now i just return promise to reject, or if continue resolve. Is there better way ?

My goal is to downloading new files. getFile

return new Promise(async (resolve, reject) => {
      //change on click for example
      if (!downloadInProgress) {
        reject("finish");
      }
      const dataToSave = {
        ...val,
        blob: new Blob([response.data], { type: val.type }),
      };
      resolve(dataToSave);

})
user2217288
  • 529
  • 2
  • 14
  • 26
  • You'd have to use a `CancelToken` (https://github.com/axios/axios#cancellation) to cancel a request. Please post the code of your `getFile` function. – frido Nov 15 '20 at 22:20
  • I'm not sure what you are trying to achieve. You are trying to cancel all files being downloaded or you are trying to cancel specific ones? Or just select certain ones to get downloaded and others not? – user1 Nov 27 '20 at 10:53
  • When user click cancel i want to cancel all future and current download. But files processed just move to subscribe as in example resolve. – user2217288 Nov 27 '20 at 14:29

0 Answers0