Struct async_unsync::unbounded::UnboundedChannel
source · pub struct UnboundedChannel<T> { /* private fields */ }Expand description
An unsynchronized (!Sync), asynchronous and unbounded channel.
Implementations§
source§impl<T> UnboundedChannel<T>
impl<T> UnboundedChannel<T>
sourcepub fn with_initial_capacity(initial: usize) -> Self
pub fn with_initial_capacity(initial: usize) -> Self
Returns a new unbounded channel with pre-allocated initial capacity.
sourcepub fn split(
&mut self
) -> (UnboundedSenderRef<'_, T>, UnboundedReceiverRef<'_, T>)
pub fn split( &mut self ) -> (UnboundedSenderRef<'_, T>, UnboundedReceiverRef<'_, T>)
Splits the channel into borrowing UnboundedSenderRef and
UnboundedReceiverRef handles.
Examples
use async_unsync::unbounded;
// must use a non-temporary binding for the channel
let mut chan = unbounded::channel();
let (tx, mut rx) = chan.split();
tx.send(1).unwrap();
// dropping the handles will close the channel
drop((tx, rx));
assert!(chan.is_closed());
// ...but the queued value can still be received
assert_eq!(chan.try_recv(), Ok(1));
assert!(chan.try_recv().is_err());sourcepub fn into_split(self) -> (UnboundedSender<T>, UnboundedReceiver<T>)
pub fn into_split(self) -> (UnboundedSender<T>, UnboundedReceiver<T>)
Splits the channel into owning UnboundedSender and
UnboundedReceiver handles.
This requires one additional allocation over
split, but avoids potential lifetime
restrictions, since the returned handles are valid for the 'static
lifetime, meaning they can be used in spawned (local) tasks.
sourcepub fn into_deque(self) -> VecDeque<T>
pub fn into_deque(self) -> VecDeque<T>
Converts into the underlying VecDeque container.
sourcepub fn try_recv(&self) -> Result<T, TryRecvError>
pub fn try_recv(&self) -> Result<T, TryRecvError>
sourcepub fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Option<T>>
pub fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Option<T>>
Polls the channel, resolving if an element was received or the channel is closed, ignoring whether there are any remaining Sender(s) or not.
Trait Implementations§
source§impl<T> Debug for UnboundedChannel<T>
impl<T> Debug for UnboundedChannel<T>
source§impl<T> FromIterator<T> for UnboundedChannel<T>
impl<T> FromIterator<T> for UnboundedChannel<T>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<T> !RefUnwindSafe for UnboundedChannel<T>
impl<T> Send for UnboundedChannel<T>where T: Send,
impl<T> !Sync for UnboundedChannel<T>
impl<T> Unpin for UnboundedChannel<T>where T: Unpin,
impl<T> UnwindSafe for UnboundedChannel<T>where T: UnwindSafe,
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
Mutably borrows from an owned value. Read more