pub struct CancellableQueue<T> { /* private fields */ }Expand description
A lock-free queue that supports active cancellation via sweeping.
Unlike mpsc channels where cancellation can only be checked at dequeue time,
this queue allows a dedicated sweeper task to iterate through queued items
and remove those belonging to cancelled transfers. This ensures that
ImmutableBlock guards are dropped promptly when a transfer is cancelled.
§Architecture
Producer ──► [SegQueue] ◄── Consumer
▲
│
[Sweeper Task]
│
(removes cancelled items)Implementations§
Source§impl<T> CancellableQueue<T>
impl<T> CancellableQueue<T>
Sourcepub fn push(&self, transfer_id: TransferId, data: T) -> bool
pub fn push(&self, transfer_id: TransferId, data: T) -> bool
Push an item onto the queue.
If the transfer has already been cancelled, the item is dropped immediately.
Returns true if the item was queued, false if it was dropped due to cancellation.
Sourcepub fn pop(&self) -> Option<QueueItem<T>>
pub fn pop(&self) -> Option<QueueItem<T>>
Pop an item from the queue.
Returns None if the queue is empty.
Items from cancelled transfers may still be returned - use pop_valid()
if you want to skip cancelled items automatically.
Sourcepub fn pop_valid(&self) -> Option<QueueItem<T>>
pub fn pop_valid(&self) -> Option<QueueItem<T>>
Pop a valid (non-cancelled) item from the queue.
Skips and drops items belonging to cancelled transfers.
Returns None if no valid items are available.
Sourcepub fn mark_cancelled(&self, transfer_id: TransferId)
pub fn mark_cancelled(&self, transfer_id: TransferId)
Mark a transfer as cancelled.
Items belonging to this transfer will be:
- Dropped immediately if pushed after this call
- Removed by the sweeper task if already in the queue
- Skipped by
pop_valid()if dequeued
Sourcepub fn is_cancelled(&self, transfer_id: TransferId) -> bool
pub fn is_cancelled(&self, transfer_id: TransferId) -> bool
Check if a transfer has been cancelled.
Sourcepub fn sweep(&self) -> usize
pub fn sweep(&self) -> usize
Remove cancelled items from the queue.
This is called by the sweeper task to actively remove items from
cancelled transfers, ensuring their resources (like ImmutableBlock guards)
are released promptly.
Returns the number of items removed.
§Implementation Note
This performs a full drain-and-requeue operation. While not ideal for very large queues, it ensures correctness with the lock-free SegQueue. For typical offload workloads (batches of 64-256 blocks), this is efficient.
Sourcepub fn clear_cancelled(&self, transfer_id: TransferId)
pub fn clear_cancelled(&self, transfer_id: TransferId)
Clear the cancelled set for a specific transfer.
Called when a transfer is fully complete to clean up the cancelled set.
Sourcepub fn len_approx(&self) -> usize
pub fn len_approx(&self) -> usize
Get the approximate queue length.
This is not exact due to concurrent modifications but useful for monitoring.
Sourcepub fn is_empty_approx(&self) -> bool
pub fn is_empty_approx(&self) -> bool
Check if the queue is approximately empty.
Sourcepub fn cancelled_count(&self) -> usize
pub fn cancelled_count(&self) -> usize
Get the number of cancelled transfers being tracked.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for CancellableQueue<T>
impl<T> !RefUnwindSafe for CancellableQueue<T>
impl<T> Send for CancellableQueue<T>where
T: Send,
impl<T> Sync for CancellableQueue<T>where
T: Send,
impl<T> Unpin for CancellableQueue<T>where
T: Unpin,
impl<T> UnsafeUnpin for CancellableQueue<T>
impl<T> UnwindSafe for CancellableQueue<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);