downloadBatch method

Future<Batch> downloadBatch(
  1. List<DownloadTask> tasks, {
  2. BatchProgressCallback? batchProgressCallback,
  3. TaskStatusCallback? taskStatusCallback,
  4. TaskProgressCallback? taskProgressCallback,
  5. void onElapsedTime(
    1. Duration
    )?,
  6. Duration? elapsedTimeInterval,
})

Enqueues a list of files to download and returns when all downloads have finished (successfully or otherwise). The returned value is a Batch object that contains the original tasks, the results and convenience getters to filter successful and failed results.

If an optional batchProgressCallback function is provided, it will be called upon completion (successfully or otherwise) of each task in the batch, with two parameters: the number of succeeded and the number of failed tasks. The callback can be used, for instance, to show a progress indicator for the batch, where double percent_complete = (succeeded + failed) / tasks.length

To also monitor status and/or progress for each task in the batch, provide a taskStatusCallback and/or taskProgressCallback, which will be used for each task in the batch.

An optional callback onElapsedTime will be called at regular intervals (defined by elapsedTimeInterval, which defaults to 5 seconds) with a single argument that is the elapsed time since the call to downloadBatch. This can be used to trigger UI warnings (e.g. 'this is taking rather long') or to cancel the task if it does not complete within a desired time. For performance reasons the elapsedTimeInterval should not be set to a value less than one second. The onElapsedTime callback should not be used to indicate progress.

Note that to allow for special processing of tasks in a batch, the task's Task.group and Task.updates value will be modified when enqueued, and those modified tasks are returned as part of the Batch object.

Implementation

Future<Batch> downloadBatch(final List<DownloadTask> tasks,
        {BatchProgressCallback? batchProgressCallback,
        TaskStatusCallback? taskStatusCallback,
        TaskProgressCallback? taskProgressCallback,
        void Function(Duration)? onElapsedTime,
        Duration? elapsedTimeInterval}) =>
    _downloader.enqueueAndAwaitBatch(tasks,
        batchProgressCallback: batchProgressCallback,
        taskStatusCallback: taskStatusCallback,
        taskProgressCallback: taskProgressCallback,
        onElapsedTime: onElapsedTime,
        elapsedTimeInterval: elapsedTimeInterval);