Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differences between checkForExistingDownloads and ensureDownloadsAreRunning? #13

Open
felipegmg opened this issue Apr 3, 2024 · 2 comments

Comments

@felipegmg
Copy link

Hi! Im in doubt which method i must use. In documentation, the "check" method is used as a preparation of "ensure" method, but in the same times, the documentation has said that those two methods are used to resume a download. So, my question is: Can I use only the checkForExistingDownloads to resume a download, in view of "ensure" method can only been used in iOS devices. Tks a Lot!

@kesha-antonov
Copy link
Owner

kesha-antonov commented Apr 3, 2024

Hi

As you can see here:

export function ensureDownloadsAreRunning () {
log('[RNBackgroundDownloader] ensureDownloadsAreRunning')
return checkForExistingDownloads()
.then(tasks => {
for (const task of tasks)
if (task.state === 'DOWNLOADING') {
task.pause()
task.resume()
}
})
}

ensureDownloadsAreRunning is just wrapper around checkForExistingDownloads to get tasks and call pause & resume on them to ensure they're running. It's good to call this method when app resumed from background - in case when you have problem when downloads stuck sometimes.

So you don't need to call checkForExistingDownloads as a preparation

@kesha-antonov
Copy link
Owner

checkForExistingDownloads is good to use on app startup when you want to re-attach those tasks to your app logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants