itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.91k stars 961 forks source link

React-native fs stops other async functions to execute until the file downloads #251

Open codesinghanoop opened 7 years ago

codesinghanoop commented 7 years ago

I am using react-native fs to download the file. The react-native fs uses promises, so until the promise is returned back it keeps other async functions in a queue to execute. For instance, If i start downloading a file then other async functions(such as getting data from local storage) gets blocked. The other async function starts executing only when the download is complete.

any help would be appreciated.

codesinghanoop commented 7 years ago

I found the solution to the issue, Adding few code to the android files will solve the above issue. I made new thread

codesinghanoop commented 7 years ago

can i contribute?

johanneslumpe commented 7 years ago

@codesinghanoop Feel free to! I cannot devote any time to this project at the moment but maybe @cjdell or other contributors can take a look at your PR.

codesinghanoop commented 7 years ago

@johanneslumpe @cjdell I have sent you the pull request, please go through it.

aengl commented 7 years ago

@codesinghanoop Had the same problem and tried your PR. Works like a charm! Thank you.

codesinghanoop commented 7 years ago

No problem friend. @johanneslumpe @cjdell please review my PR, it's helpful.

br4nnigan commented 7 years ago

is it possible that currently downloads block each other in that manner? That means only one download at a time. I have this impression but will investigate further.

codesinghanoop commented 7 years ago

No two parallel download will work. Second download will proceed after first download is done successfully.....

itinance commented 7 years ago

maybe we should start each download task in a separate thread? For android there is already a PR from @codesinghanoop https://github.com/itinance/react-native-fs/pull/254

codesinghanoop commented 7 years ago

@itinance Thanks for the reference sir..

itinance commented 7 years ago

If we would parallelize all download task with next release, some apps could get in trouble than maybe. For keeping backward compat i would suggest to add an optional separateThread-Mode. If this is true, the downloadTask would start in a separate thread, otherwise not.

codesinghanoop commented 7 years ago

Yes that's a good idea...

codesinghanoop commented 7 years ago

Hi guys, According to me we have to add a new thread to write(download) the file and my research says that would not affect other things. We are basically adding thread only for writing(downloading) the files.

itinance commented 7 years ago

And you use the code of your PR for this, right? https://github.com/itinance/react-native-fs/pull/254 Then i will speed it up in upcoming days to test and merge

codesinghanoop commented 7 years ago

Yes, sir right..

itinance commented 7 years ago

Ok thank you! I will do the same on iOS side and merge it then together with your PR. Tomorrow or on Monday.

codesinghanoop commented 7 years ago

cool :+1:

itinance commented 7 years ago

I will merge this in upcoming days, together with a solution for iOS also by my own. Thought i could do this much faster but it will take some days.

codesinghanoop commented 7 years ago

Yeah, no problem ..Thank you :)

anshul-kai commented 6 years ago

Hi guys! Thanks for the research around this. It would be great to parallelize downloads.

@itinance, why do you think that parallelizing may cause issues on some devices?

itinance commented 6 years ago

Because multithreading is often a pain to debug. Also we don't know if any apps would come into trouble when downloads now would be run in parallel. But for next release i will add a note that we've changed the Download-Task to Threads now. /cc @a-koka

Anyway I just merged #254 for android. Need to do this also for iOS or someone wants to send a PR for it?

zoecarver commented 6 years ago

@itinance Has this been released yet? I am having the same issue when I use the react-native-fs npm module.

codesinghanoop commented 6 years ago

is it for iOS or Android ?

zoecarver commented 6 years ago

Android for now (but I am hoping to include iOS later)

codesinghanoop commented 6 years ago

I'm assuming you are using current version of this lib. Please can you install v2.5 and let me know if you are still facing the same issue.

zoecarver commented 6 years ago

That fixed it! Thank you so much! Why is this not in the current version?

codesinghanoop commented 6 years ago

i don't know or may be some new functionality is destroying this. @itinance