@@ -9,6 +9,7 @@ use super::common::SubscriptionFuncStream;
9
9
10
10
use super :: common:: { Observable , RawFunc , Subscription , SubscriptionFunc , UniqueId } ;
11
11
use super :: handler:: Handler ;
12
+ use super :: sync:: { BlockingQueue , Queue } ;
12
13
13
14
/**
14
15
The `Publisher` implements *PubSub-like* features.
@@ -43,7 +44,7 @@ impl<X> Default for Publisher<X> {
43
44
}
44
45
}
45
46
46
- impl < X : Send + Sync + ' static > Publisher < X > {
47
+ impl < X > Publisher < X > {
47
48
pub fn new ( ) -> Publisher < X > {
48
49
Default :: default ( )
49
50
}
@@ -53,6 +54,14 @@ impl<X: Send + Sync + 'static> Publisher<X> {
53
54
new_one
54
55
}
55
56
57
+ pub fn subscribe_on ( & mut self , h : Option < Arc < Mutex < dyn Handler + ' static > > > ) {
58
+ self . sub_handler = h;
59
+ }
60
+ }
61
+ impl < X > Publisher < X >
62
+ where
63
+ X : Send + Sync + ' static ,
64
+ {
56
65
pub fn publish ( & mut self , val : X ) {
57
66
self . notify_observers ( Arc :: new ( val) ) ;
58
67
}
@@ -85,8 +94,18 @@ impl<X: Send + Sync + 'static> Publisher<X> {
85
94
self . delete_observer ( s) ;
86
95
}
87
96
88
- pub fn subscribe_on ( & mut self , h : Option < Arc < Mutex < dyn Handler + ' static > > > ) {
89
- self . sub_handler = h;
97
+ pub fn subscribe_blocking_queue (
98
+ & mut self ,
99
+ queue : Arc < Mutex < BlockingQueue < Arc < X > > > > ,
100
+ ) -> Arc < Mutex < SubscriptionFunc < X > > > {
101
+ self . subscribe_fn ( move |v| queue. lock ( ) . unwrap ( ) . offer ( v) )
102
+ }
103
+ pub fn as_blocking_queue ( & mut self ) -> BlockingQueue < Arc < X > > {
104
+ let queue = BlockingQueue :: new ( ) ;
105
+ let queue_result = queue. clone ( ) ;
106
+ self . subscribe_blocking_queue ( Arc :: new ( Mutex :: new ( queue) ) ) ;
107
+
108
+ queue_result
90
109
}
91
110
}
92
111
0 commit comments