Skip to main content

download

Function download 

Source
pub fn download(
    url: Url,
    partial_config: PartialConfig,
    tx: Tx,
    token: CancellationToken,
)
Expand description

Spawn a detached background download task that resumes automatically when possible.

This is the one-shot form of plan followed by DownloadPlan::start: the task prefetches metadata, then either resumes from a valid .fd/.part state or starts a fresh download (falling back silently when resume is impossible). Use plan directly when the decision should be shown to a user first. Progress and lifecycle events are delivered through tx.

The run always ends with exactly one Event::Terminated, which is the last event on the channel — including when planning itself fails or is cancelled. A caller can wait for it instead of draining rx until it disconnects; the channel still disconnects afterwards, because the spawned task holds the only Tx clones. Keep the CancellationToken you passed in if you need to cancel.