Skip to main content

base_scheduler/
notify.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::Cancellation;
5use std::sync::{Arc, mpsc};
6
7/// A synchronous destination for a notification value.
8///
9/// Called in ordinary thread context, never directly in a raw signal handler. Implementations should return promptly: enqueue work or wake a future rather than waiting for it to finish. Waiting remains specific to the destination.
10///
11/// Channel implementations enqueue without waiting for capacity. A closed receiver discards the value. Bounded senders have no default implementation: an application must choose its own overflow policy in a wrapper.
12pub trait Notify<Value>: Send + Sync {
13    fn notify(&self, value: Value);
14}
15
16impl<Value> Notify<Value> for Cancellation {
17    fn notify(&self, _value: Value) {
18        self.cancel();
19    }
20}
21
22impl<Value, Target: Notify<Value> + ?Sized> Notify<Value> for Arc<Target> {
23    fn notify(&self, value: Value) {
24        (**self).notify(value);
25    }
26}
27
28impl<Value: Send> Notify<Value> for mpsc::Sender<Value> {
29    fn notify(&self, value: Value) {
30        let _ = self.send(value);
31    }
32}