Skip to main content

DownloadResult

Struct DownloadResult 

Source
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>
where E: Executor + Send + Sync, PullError: Send + Unpin + 'static, PushError: Send + Unpin + 'static,

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_aborted(&self) -> bool

Whether the session has been (or is being) cancelled.

Trait Implementations§

Source§

impl<E, PullError, PushError> Clone for DownloadResult<E, PullError, PushError>
where E: Executor + Send + Sync, PullError: Send + Unpin + 'static, PushError: Send + Unpin + 'static,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E, PullError, PushError> Debug for DownloadResult<E, PullError, PushError>
where E: Executor + Send + Sync, PullError: Send + Unpin + 'static, PushError: Send + Unpin + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E, PullError, PushError> !RefUnwindSafe for DownloadResult<E, PullError, PushError>

§

impl<E, PullError, PushError> !UnwindSafe for DownloadResult<E, PullError, PushError>

§

impl<E, PullError, PushError> Freeze for DownloadResult<E, PullError, PushError>
where Arc<DownloadResultInner<E, PullError, PushError>>: Freeze,

§

impl<E, PullError, PushError> Send for DownloadResult<E, PullError, PushError>
where Arc<DownloadResultInner<E, PullError, PushError>>: Send,

§

impl<E, PullError, PushError> Sync for DownloadResult<E, PullError, PushError>
where Arc<DownloadResultInner<E, PullError, PushError>>: Sync,

§

impl<E, PullError, PushError> Unpin for DownloadResult<E, PullError, PushError>
where Arc<DownloadResultInner<E, PullError, PushError>>: Unpin,

§

impl<E, PullError, PushError> UnsafeUnpin for DownloadResult<E, PullError, PushError>
where Arc<DownloadResultInner<E, PullError, PushError>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.