File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,19 @@ pub struct TickedAsyncExecutor<O> {
24
24
channel : ( mpsc:: Sender < Payload > , mpsc:: Receiver < Payload > ) ,
25
25
num_woken_tasks : Arc < AtomicUsize > ,
26
26
num_spawned_tasks : Arc < AtomicUsize > ,
27
+
28
+ // TODO, Or we need a Single Producer - Multi Consumer channel i.e Broadcast channel
29
+ // Broadcast recv channel should be notified when there are new messages in the queue
30
+ // Broadcast channel must also be able to remove older/stale messages (like a RingBuffer)
27
31
observer : O ,
28
32
}
29
33
34
+ impl Default for TickedAsyncExecutor < fn ( TaskState ) > {
35
+ fn default ( ) -> Self {
36
+ Self :: new ( |_| { } )
37
+ }
38
+ }
39
+
30
40
impl < O > TickedAsyncExecutor < O >
31
41
where
32
42
O : Fn ( TaskState ) + Clone + Send + Sync + ' static ,
78
88
79
89
/// Run the woken tasks once
80
90
///
91
+ /// Tick is !Sync i.e cannot be invoked from multiple threads
92
+ ///
81
93
/// NOTE: Will not run tasks that are woken/scheduled immediately after `Runnable::run`
82
94
pub fn tick ( & self ) {
83
95
let num_woken_tasks = self . num_woken_tasks . load ( Ordering :: Relaxed ) ;
@@ -135,7 +147,7 @@ mod tests {
135
147
136
148
#[ test]
137
149
fn test_multiple_tasks ( ) {
138
- let executor = TickedAsyncExecutor :: new ( |_state| { } ) ;
150
+ let executor = TickedAsyncExecutor :: default ( ) ;
139
151
executor
140
152
. spawn_local ( "A" , async move {
141
153
tokio:: task:: yield_now ( ) . await ;
You can’t perform that action at this time.
0 commit comments