pub struct UnorderedDownloadStream { /* private fields */ }Expand description
A streaming download handle that yields data chunks in completion order, each tagged with its byte offset in the output file.
Created by FileReconstructor::reconstruct_to_unordered_stream. The
reconstruction task is spawned immediately but pauses until
start is called (or the first next /
blocking_next). Because the tokio::spawn
happens at construction time, subsequent calls to start(), next(),
and blocking_next() do not require a tokio runtime context.
Unlike DownloadStream, data
chunks may arrive out of order. Each chunk is returned as (offset, Bytes)
so the consumer knows where it belongs. Progress can be monitored via
the tracking methods which read shared atomic counters.
Holds only Arc<WriterProgress>, not the writer itself, so the channel
sender is dropped naturally when the reconstruction task finishes.
Implementations§
Source§impl UnorderedDownloadStream
impl UnorderedDownloadStream
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Unblocks the reconstruction task so it begins producing data.
If already started, this is a no-op. Called automatically on the first
next / blocking_next.
This method is non-async and does not require a tokio runtime context.
Sourcepub fn blocking_next(&mut self) -> Result<Option<(u64, Bytes)>>
pub fn blocking_next(&mut self) -> Result<Option<(u64, Bytes)>>
Returns the next chunk of downloaded data with its byte offset, blocking the current thread until data is available.
Returns Ok(None) when the download is complete.
§Panics
Panics if called from within an async runtime context. Use from a
regular thread or from tokio::task::spawn_blocking instead.
For the async-safe variant, use next.
Sourcepub async fn next(&mut self) -> Result<Option<(u64, Bytes)>>
pub async fn next(&mut self) -> Result<Option<(u64, Bytes)>>
Returns the next chunk of downloaded data with its byte offset asynchronously.
Returns Ok(None) when the download is complete.
Sourcepub fn cancel(&mut self)
pub fn cancel(&mut self)
Cancels the in-progress (or not-yet-started) download.
Signals the shared run state so the reconstruction loop aborts at its
next check point. After calling this, subsequent calls to
blocking_next / next will
return Ok(None).
Sourcepub fn total_bytes_expected(&self) -> u64
pub fn total_bytes_expected(&self) -> u64
Total bytes expected for the reconstruction, read from the progress updater. Returns 0 if not yet known or no progress updater is set.
Sourcepub fn bytes_in_progress(&self) -> u64
pub fn bytes_in_progress(&self) -> u64
Bytes currently being fetched by in-progress tasks.
Sourcepub fn bytes_completed(&self) -> u64
pub fn bytes_completed(&self) -> u64
Bytes that have been delivered through the progress updater. Returns 0 if no progress updater is set.
Sourcepub fn terms_in_progress(&self) -> u64
pub fn terms_in_progress(&self) -> u64
Number of tasks currently resolving data futures.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true once the stream has reached terminal state.
This flips to true after next / blocking_next
has observed the end-of-stream (None), or after cancel.
Buffered but unconsumed channel items do not count as complete.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UnorderedDownloadStream
impl RefUnwindSafe for UnorderedDownloadStream
impl Send for UnorderedDownloadStream
impl Sync for UnorderedDownloadStream
impl Unpin for UnorderedDownloadStream
impl UnsafeUnpin for UnorderedDownloadStream
impl UnwindSafe for UnorderedDownloadStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more