Skip to main content

WeakTx

Struct WeakTx 

Source
pub struct WeakTx<F: Flavor + FlavorMP>(/* private fields */);
Expand description

A weak reference of SenderType

Can be obtain from MTx::downgrade or MAsyncTx::downgrade. When the number of valid sender is non-zero, can try upgrade to a MTx or MAsyncTx.

Implementations§

Source§

impl<F: Flavor + FlavorMP> WeakTx<F>

Source

pub fn upgrade<S: SenderType<Flavor = F>>(&self) -> Option<S>

Upgrade to MTx or MAsyncTx (Only allow for mpsc or mpmc)

§Safety

Warning: You should be careful using this on a bounded channel receiver-side (Because when the channel is full and send() blocks while no one is receiving, will result in dead-lock)

§Example
use crossfire::*;
let (tx, rx) = mpsc::bounded_blocking::<usize>(100);
let weak_tx = tx.downgrade();
let tx_clone = weak_tx.upgrade::<MTx<_>>().unwrap();
drop(tx);
drop(tx_clone);
assert!(weak_tx.upgrade::<MTx<_>>().is_none());
assert_eq!(weak_tx.get_tx_count(), 0);
drop(rx);
Source

pub fn get_tx_count(&self) -> usize

Source

pub fn get_rx_count(&self) -> usize

Source§

impl<F> WeakTx<F>

Source

pub unsafe fn send_unchecked(&self, item: F::Item)

Sends a message without checking channel closed first (Only available for unbounded channel)

It’s for scenario that receiver-side never exit early, but they holds a WeakTx to re-submit message. NOTE that it will not faster than send(), just useful save the operation of upgrade() if you don’t care about the error.

Always success, never blocked, no return type.

§Safety

It may result in message send successfully without anyone to receive them. You have to rely on the Drop trait of the message to cleanup.

Trait Implementations§

Auto Trait Implementations§

§

impl<F> Freeze for WeakTx<F>

§

impl<F> RefUnwindSafe for WeakTx<F>

§

impl<F> Unpin for WeakTx<F>

§

impl<F> UnsafeUnpin for WeakTx<F>

§

impl<F> UnwindSafe for WeakTx<F>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.