React-native-fs: get the download job id before the download actually starts [feature requests]

Created on 8 Aug 2016  路  4Comments  路  Source: itinance/react-native-fs

if i have a list of available downloads (app interface), i'm able to begin the download of each one even if another hasn't finished, but, if i cancel one that has not really started downloading (onBegin callback has not being called), i get an error because i still don't have the actual jobId.

i think that if we get the job id when we just started the download, this could be fixed, is it possible?

Most helpful comment

All 4 comments

@CesarLanderos We could return the jobId synchronously.

So instead of returning just the promise, we could return something like:

{
  jobId: 1,
  promise: <Promise>
}

What do you think? We're in the process of releasing V2, so now is the time to be making breaking changes such as this one. :-)

Great!, and yeah!, definitely most be asynchronous, but with this approach, i have just one concern, its not really bad.

I am working in an app in wich a user can download certain contents, each content has many files to download, so i make use (extensively) of Promise.all()

For example:

Promise.all(files.map(file =>
    RNFS.download(options)
))
.then(results =>
    // done
);

But well, i will just have to make some adjustments to the map function, it will not be as clean as before, but is cleaner that the workaround that i had to make, than consisted on deleting the content from the downloaded contents db, and when the onBegin callback gets called, i check if the content still exists in the db, if not then immediately stops the download, it is not very semantic to be honest :p

Typo!, must be synchronous, not asynchronous hehe.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wangfpp picture wangfpp  路  3Comments

AbdelkaderOumrani picture AbdelkaderOumrani  路  3Comments

crobinson42 picture crobinson42  路  4Comments

AgNm picture AgNm  路  4Comments

JohnRyanTsai picture JohnRyanTsai  路  3Comments