What is the best way to pause and resume all downloads from a certain group? #465
-
Currently, I'm doing something like below but it feels a bit clunky. Is there a better way? @override
Future<void> pauseAll(String group) async {
final tasks = await FileDownloader().allTasks(
group: group,
);
final taskFutures = tasks
.whereType<DownloadTask>()
.map((task) => FileDownloader().pause(task))
.toList();
await Future.wait(taskFutures);
}
@override
Future<void> resumeAll(String group) async {
final tasks = await FileDownloader().allTasks(
group: group,
);
final taskFutures = tasks
.whereType<DownloadTask>()
.map((task) => FileDownloader().resume(task))
.toList();
await Future.wait(taskFutures);
} |
Beta Was this translation helpful? Give feedback.
Answered by
781flyingdutchman
Feb 25, 2025
Replies: 1 comment 3 replies
-
This is the right way to do it - if you have a lot of tasks you may want to do a more sophisticated throttling/pacing of the calls to |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
khoadng
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the right way to do it - if you have a lot of tasks you may want to do a more sophisticated throttling/pacing of the calls to
pause
anresume
to avoid starving the UI thread. I may look into addingpauseAll
andresumeAll
that take a list of tasks and managing the pause/resume pacing.