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> !Freeze for UnboundedChannel<T>
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