Skip to content

Commit

Permalink
Made new thread for other native processes
Browse files Browse the repository at this point in the history
  • Loading branch information
codesinghanoop committed Feb 14, 2017
1 parent e212728 commit ad36b07
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions android/src/main/java/com/rnfs/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@
public class Downloader extends AsyncTask<DownloadParams, int[], DownloadResult> {
private DownloadParams mParam;
private AtomicBoolean mAbort = new AtomicBoolean(false);
DownloadResult res;

protected DownloadResult doInBackground(DownloadParams... params) {
mParam = params[0];

DownloadResult res = new DownloadResult();

try {
this.download(mParam, res);
mParam.onTaskCompleted.onTaskCompleted(res);
} catch (Exception ex) {
res.exception = ex;
mParam.onTaskCompleted.onTaskCompleted(res);
return res;
}
res = new DownloadResult();

new Thread(new Runnable() {
public void run() {
try {
download(mParam, res);
mParam.onTaskCompleted.onTaskCompleted(res);
} catch (Exception ex) {
res.exception = ex;
mParam.onTaskCompleted.onTaskCompleted(res);
}
}
}).start();

return res;
}
Expand Down

6 comments on commit ad36b07

@punksta
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello!
Could you explain the the goal of this change?

@itinance
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will start any download with a new thread

@punksta
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that it's unnecessary job. doInBackground is executed on default thread pool with maxing 2*(core number)+1 threads.

if you don't want to fill default pool queue, you can create special executor.

@itinance
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets discuss with @codesinghanoop, otherwise you can every time provide a new pull request with better approaches. What do you think?

@punksta
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to notice this. I will create pl latter, sure.

@codesinghanoop
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@punksta provide a PR if you have better solution i will review it.

Please sign in to comment.