pub struct DownloadResult<E, PullError, PushError>where
E: Executor + Send + Sync,
PullError: Send + Unpin + 'static,
PushError: Send + Unpin + 'static,{ /* private fields */ }Expand description
Handle to an active download session.
Cheaply cloneable shared handle. The underlying download keeps running as
long as any clone is alive, and is cancelled only once the last clone is
dropped. An explicit abort cancels immediately.
DownloadResult wraps Arc<DownloadResultInner> and exposes the session
methods (abort, set_threads, is_aborted) and
event_chain directly; each delegates to the inner
value. There is intentionally no Deref impl — DownloadResultInner
is private, so callers reach session state only through these methods.
Completion is observed by draining event_chain: once
the last sender is dropped (the download finished or was aborted) the
receiver disconnects, so while result.event_chain().recv().await.is_ok() {}
awaits the session end.
Implementations§
Source§impl<E, PullError, PushError> DownloadResult<E, PullError, PushError>
impl<E, PullError, PushError> DownloadResult<E, PullError, PushError>
Sourcepub fn new(
event_chain: MAsyncRx<List<Event<PullError, PushError>>>,
task_queue: Option<(E, TaskQueue<E::Handle>)>,
abort_token: CancellationToken,
) -> Self
pub fn new( event_chain: MAsyncRx<List<Event<PullError, PushError>>>, task_queue: Option<(E, TaskQueue<E::Handle>)>, abort_token: CancellationToken, ) -> Self
Construct a DownloadResult from the raw session pieces.
This is an internal constructor used by
download_single and
download_multi; prefer those entry
points instead of calling this directly.
Sourcepub fn event_chain(&self) -> &MAsyncRx<List<Event<PullError, PushError>>>
pub fn event_chain(&self) -> &MAsyncRx<List<Event<PullError, PushError>>>
Access the stream of Events emitted during the session.
The receiver closes once the last clone of this handle is dropped or the session is aborted, so draining it is a natural way to observe progress.
Sourcepub fn abort(&self)
pub fn abort(&self)
Cancel all workers immediately.
Safe to call multiple times and safe to call while other clones of the
owning DownloadResult are still alive. The implicit drop-based
cancellation (on the last clone) becomes a no-op once this has run.
Sourcepub fn set_threads(&self, threads: usize, min_chunk_size: u64)
pub fn set_threads(&self, threads: usize, min_chunk_size: u64)
Adjust the worker thread count and minimum chunk size of a running multi-threaded session.
Growing spawns workers for ranges still waiting in the queue, or splits a range off the busiest running worker when nothing is waiting. Shrinking aborts the surplus workers and returns their ranges to the queue for the survivors to steal. No-op for single-threaded sessions, which have no task queue.
A session ends when its last worker exits, and it cannot be restarted:
growing afterwards spawns nothing, because the workers’ shared channels
are closed at that point. Shrinking is clamped to a minimum of one worker
by the scheduler, so set_threads(0) keeps a single worker alive rather
than ending the session. The session terminates only when that last
(clamped) worker exits on its own.
This never touches the abort token: abort is terminal and
cannot be undone by resizing, so is_aborted stays
true across any later set_threads call, and any worker spawned by such
a call observes the cancelled token and exits without pulling.
Sourcepub fn is_aborted(&self) -> bool
pub fn is_aborted(&self) -> bool
Whether the session has been (or is being) cancelled.