diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-10-21 10:48:07 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-10-21 10:48:07 +0200 |
| commit | 379a59329158febc8edce1d62f62c07d71f22105 (patch) | |
| tree | 9088ec503b56f284ba2747da3ccdb46a16b5b6b3 /embassy-sync/src/pubsub/mod.rs | |
| parent | e8ba9696f140e604344d84fba93bd9854de56c0a (diff) | |
| parent | 89bad07e817dec482d385f765da5be3b6d2d0e4c (diff) | |
Merge pull request #3358 from mammothbane/main
embassy_sync: `Sink` adapter for `pubsub::Pub`
Diffstat (limited to 'embassy-sync/src/pubsub/mod.rs')
| -rw-r--r-- | embassy-sync/src/pubsub/mod.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/embassy-sync/src/pubsub/mod.rs b/embassy-sync/src/pubsub/mod.rs index ae5951829..a2360a1d8 100644 --- a/embassy-sync/src/pubsub/mod.rs +++ b/embassy-sync/src/pubsub/mod.rs | |||
| @@ -755,4 +755,30 @@ mod tests { | |||
| 755 | assert_eq!(1, sub0.try_next_message_pure().unwrap().0); | 755 | assert_eq!(1, sub0.try_next_message_pure().unwrap().0); |
| 756 | assert_eq!(0, sub1.try_next_message_pure().unwrap().0); | 756 | assert_eq!(0, sub1.try_next_message_pure().unwrap().0); |
| 757 | } | 757 | } |
| 758 | |||
| 759 | #[futures_test::test] | ||
| 760 | async fn publisher_sink() { | ||
| 761 | use futures_util::{SinkExt, StreamExt}; | ||
| 762 | |||
| 763 | let channel = PubSubChannel::<NoopRawMutex, u32, 4, 4, 4>::new(); | ||
| 764 | |||
| 765 | let mut sub = channel.subscriber().unwrap(); | ||
| 766 | |||
| 767 | let publ = channel.publisher().unwrap(); | ||
| 768 | let mut sink = publ.sink(); | ||
| 769 | |||
| 770 | sink.send(0).await.unwrap(); | ||
| 771 | assert_eq!(0, sub.try_next_message_pure().unwrap()); | ||
| 772 | |||
| 773 | sink.send(1).await.unwrap(); | ||
| 774 | assert_eq!(1, sub.try_next_message_pure().unwrap()); | ||
| 775 | |||
| 776 | sink.send_all(&mut futures_util::stream::iter(0..4).map(Ok)) | ||
| 777 | .await | ||
| 778 | .unwrap(); | ||
| 779 | assert_eq!(0, sub.try_next_message_pure().unwrap()); | ||
| 780 | assert_eq!(1, sub.try_next_message_pure().unwrap()); | ||
| 781 | assert_eq!(2, sub.try_next_message_pure().unwrap()); | ||
| 782 | assert_eq!(3, sub.try_next_message_pure().unwrap()); | ||
| 783 | } | ||
| 758 | } | 784 | } |
