Skip to content

Commit b31066a

Browse files
committed
Added default for observer using function ptr i.e
fn(TaskState)
1 parent cdad331 commit b31066a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/ticked_async_executor.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ pub struct TickedAsyncExecutor<O> {
2424
channel: (mpsc::Sender<Payload>, mpsc::Receiver<Payload>),
2525
num_woken_tasks: Arc<AtomicUsize>,
2626
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)
2731
observer: O,
2832
}
2933

34+
impl Default for TickedAsyncExecutor<fn(TaskState)> {
35+
fn default() -> Self {
36+
Self::new(|_| {})
37+
}
38+
}
39+
3040
impl<O> TickedAsyncExecutor<O>
3141
where
3242
O: Fn(TaskState) + Clone + Send + Sync + 'static,
@@ -78,6 +88,8 @@ where
7888

7989
/// Run the woken tasks once
8090
///
91+
/// Tick is !Sync i.e cannot be invoked from multiple threads
92+
///
8193
/// NOTE: Will not run tasks that are woken/scheduled immediately after `Runnable::run`
8294
pub fn tick(&self) {
8395
let num_woken_tasks = self.num_woken_tasks.load(Ordering::Relaxed);
@@ -135,7 +147,7 @@ mod tests {
135147

136148
#[test]
137149
fn test_multiple_tasks() {
138-
let executor = TickedAsyncExecutor::new(|_state| {});
150+
let executor = TickedAsyncExecutor::default();
139151
executor
140152
.spawn_local("A", async move {
141153
tokio::task::yield_now().await;

0 commit comments

Comments
 (0)