Skip to main content

aimdb_executor/
join.rs

1use core::future::Future;
2
3use crate::{ExecutorResult, Spawn};
4
5/// Runtime capability for creating join fan-in queues.
6///
7/// Implemented by each runtime adapter. Queue capacity is an internal
8/// constant chosen per adapter (Tokio: 64, Embassy: 8, WASM: 64).
9pub trait JoinFanInRuntime: Spawn {
10    type JoinQueue<T: Send + 'static>: JoinQueue<T>;
11
12    fn create_join_queue<T: Send + 'static>(&self) -> ExecutorResult<Self::JoinQueue<T>>;
13}
14
15/// A bounded fan-in queue that can be split into a sender/receiver pair.
16pub trait JoinQueue<T: Send + 'static> {
17    type Sender: JoinSender<T> + Clone + Send + 'static;
18    type Receiver: JoinReceiver<T> + Send + 'static;
19
20    fn split(self) -> (Self::Sender, Self::Receiver);
21}
22
23/// The sending half of a join fan-in queue.
24///
25/// `send` may await when the queue is full (bounded backpressure).
26/// Returns `Err(QueueClosed)` if the receiver has been dropped.
27pub trait JoinSender<T: Send + 'static> {
28    fn send(&self, item: T) -> impl Future<Output = ExecutorResult<()>> + Send + '_;
29}
30
31/// The receiving half of a join fan-in queue.
32///
33/// Returns `Err(QueueClosed)` when all senders have been dropped.
34pub trait JoinReceiver<T: Send + 'static> {
35    fn recv(&mut self) -> impl Future<Output = ExecutorResult<T>> + Send + '_;
36}