pub trait WakeSource: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn subscribe<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, WakeEvent>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn cron_expression(&self) -> Option<&str> { ... }
}Expand description
A source of wake events: an adapter over adk_agent::ambient::EventSource where one
exists (spec 3.2 §7.4).
Every source sets WakeEvent::key (§13 Q7). A third-party source with a natural
delivery id, such as a provider’s event id, implements this and sets the key from it.
§Example
use adk_kernel::{WakeEvent, WakeSource};
use async_trait::async_trait;
use futures::stream::{self, BoxStream, StreamExt};
struct Deliveries(Vec<(String, serde_json::Value)>);
#[async_trait]
impl WakeSource for Deliveries {
fn name(&self) -> &str {
"provider"
}
async fn subscribe(&self) -> adk_kernel::Result<BoxStream<'static, WakeEvent>> {
let events: Vec<WakeEvent> = self
.0
.iter()
.map(|(id, payload)| WakeEvent::new("provider", format!("provider:{id}"), payload.clone()))
.collect();
Ok(stream::iter(events).boxed())
}
}Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
The source’s name, recorded as WakeEvent::source.
Sourcefn subscribe<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, WakeEvent>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn subscribe<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, WakeEvent>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Subscribes to the source’s events until the stream is dropped.
§Errors
Returns an error when the source cannot start, such as a watch on a missing directory.
Provided Methods§
Sourcefn cron_expression(&self) -> Option<&str>
fn cron_expression(&self) -> Option<&str>
The cron expression the source ticks on, when it is a cron source that names one
(spec 3.5 §7.11): the kernel adds no source of its own for a standing trigger’s
expression a registered source ticks on. None by default.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".