11use futures:: future:: BoxFuture ;
22use futures:: FutureExt ;
3- use tokio:: sync:: broadcast:: error:: SendError ;
3+ use tokio:: sync:: broadcast:: error:: { RecvError , SendError } ;
44use tokio:: sync:: broadcast:: { self } ;
55
6+ use crate :: receiver:: Receiver ;
67use crate :: sender:: Sender ;
78
89const CHANNEL_CAPACITY : usize = 32768 ;
@@ -13,14 +14,6 @@ pub struct Broadcaster<E: Sync + Send + Clone> {
1314 pub ( crate ) sender : broadcast:: Sender < E > ,
1415}
1516
16- impl < E : Sync + Send + Clone > Sender for Broadcaster < E > {
17- type Event = E ;
18-
19- fn send_event ( & self , event : E ) -> BoxFuture < ' _ , Option < Result < usize , SendError < E > > > > {
20- async move { Some ( self . sender . send ( event) ) } . boxed ( )
21- }
22- }
23-
2417impl < E : Sync + Send + Clone > Default for Broadcaster < E > {
2518 fn default ( ) -> Self {
2619 let ( sender, _) = broadcast:: channel ( CHANNEL_CAPACITY ) ;
@@ -34,3 +27,19 @@ impl<E: Sync + Send + Clone> Broadcaster<E> {
3427 self . sender . subscribe ( )
3528 }
3629}
30+
31+ impl < E : Sync + Send + Clone > Sender for Broadcaster < E > {
32+ type Event = E ;
33+
34+ fn send_event ( & self , event : E ) -> BoxFuture < ' _ , Option < Result < usize , SendError < E > > > > {
35+ async move { Some ( self . sender . send ( event) ) } . boxed ( )
36+ }
37+ }
38+
39+ impl < E : Sync + Send + Clone > Receiver for broadcast:: Receiver < E > {
40+ type Event = E ;
41+
42+ fn recv ( & mut self ) -> BoxFuture < ' _ , Result < Self :: Event , RecvError > > {
43+ async move { self . recv ( ) . await } . boxed ( )
44+ }
45+ }
0 commit comments