Merge pull request #2648 from peterkrull/dyn-channel-constructor
Add constructor for dynamic channel
This commit is contained in:
commit
20760ff4f7
1 changed files with 21 additions and 1 deletions
|
@ -507,6 +507,16 @@ where
|
|||
Receiver { channel: self }
|
||||
}
|
||||
|
||||
/// Get a sender for this channel using dynamic dispatch.
|
||||
pub fn dyn_sender(&self) -> DynamicSender<'_, T> {
|
||||
DynamicSender { channel: self }
|
||||
}
|
||||
|
||||
/// Get a receiver for this channel using dynamic dispatch.
|
||||
pub fn dyn_receiver(&self) -> DynamicReceiver<'_, T> {
|
||||
DynamicReceiver { channel: self }
|
||||
}
|
||||
|
||||
/// Send a value, waiting until there is capacity.
|
||||
///
|
||||
/// Sending completes when the value has been pushed to the channel's queue.
|
||||
|
@ -648,7 +658,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic_dispatch() {
|
||||
fn dynamic_dispatch_into() {
|
||||
let c = Channel::<NoopRawMutex, u32, 3>::new();
|
||||
let s: DynamicSender<'_, u32> = c.sender().into();
|
||||
let r: DynamicReceiver<'_, u32> = c.receiver().into();
|
||||
|
@ -657,6 +667,16 @@ mod tests {
|
|||
assert_eq!(r.try_receive().unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic_dispatch_constructor() {
|
||||
let c = Channel::<NoopRawMutex, u32, 3>::new();
|
||||
let s = c.dyn_sender();
|
||||
let r = c.dyn_receiver();
|
||||
|
||||
assert!(s.try_send(1).is_ok());
|
||||
assert_eq!(r.try_receive().unwrap(), 1);
|
||||
}
|
||||
|
||||
#[futures_test::test]
|
||||
async fn receiver_receives_given_try_send_async() {
|
||||
let executor = ThreadPool::new().unwrap();
|
||||
|
|
Loading…
Reference in a new issue