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 /// Deliver `value` to this destination. Implementations should return promptly.
14 fn notify(&self, value: Value);
15}
16
17impl<Value> Notify<Value> for Cancellation {
18 fn notify(&self, _value: Value) {
19 self.cancel();
20 }
21}
22
23impl<Value, Target: Notify<Value> + ?Sized> Notify<Value> for Arc<Target> {
24 fn notify(&self, value: Value) {
25 (**self).notify(value);
26 }
27}
28
29impl<Value: Send> Notify<Value> for mpsc::Sender<Value> {
30 fn notify(&self, value: Value) {
31 let _ = self.send(value);
32 }
33}