pub trait PollTask<TState, TResourceKey = Cow<'static, str>>: Send + Syncwhere
TState: Clone + Debug + Send + Sync + 'static,
TResourceKey: Hash + Eq + Send + Sync + 'static,{
// Required method
fn poll<'life0, 'life1, 'async_trait>(
&'life0 self,
res: &'life1 Resources<TResourceKey>,
) -> Pin<Box<dyn Future<Output = Result<PollOutcome<TState>, CanoError>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn config(&self) -> TaskConfig { ... }
fn name(&self) -> Cow<'static, str> { ... }
fn on_poll_error(&self) -> PollErrorPolicy { ... }
}Expand description
A “wait-until” processing model that repeatedly calls poll until
it returns PollOutcome::Ready.
§Generic Types
TState: The state enum used by the workflow (Clone + Debug + Send + Sync).TResourceKey: The key type used to look up resources (defaults toCow<'static, str>).
§Default config
Unlike RouterTask, PollTask defaults to
TaskConfig::minimal() (no retries). The poll loop itself is the resilience
mechanism; outer retry wrapping rarely makes sense here.
§Implementing PollTask
Prefer the inherent #[task::poll(state = S)] form:
use cano::prelude::*;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Step { Wait, Done }
struct MyPoller;
#[task::poll(state = Step)]
impl MyPoller {
async fn poll(&self, _res: &Resources) -> Result<PollOutcome<Step>, CanoError> {
Ok(PollOutcome::Ready(TaskResult::Single(Step::Done)))
}
}Required Methods§
Sourcefn poll<'life0, 'life1, 'async_trait>(
&'life0 self,
res: &'life1 Resources<TResourceKey>,
) -> Pin<Box<dyn Future<Output = Result<PollOutcome<TState>, CanoError>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn poll<'life0, 'life1, 'async_trait>(
&'life0 self,
res: &'life1 Resources<TResourceKey>,
) -> Pin<Box<dyn Future<Output = Result<PollOutcome<TState>, CanoError>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Call once per poll iteration.
Return PollOutcome::Ready with the next TaskResult when the condition is met,
or PollOutcome::Pending with a sleep duration when it is not yet ready.
§Errors
Returns CanoError on a non-recoverable error. The loop’s response to the
error is governed by on_poll_error.
Provided Methods§
Sourcefn config(&self) -> TaskConfig
fn config(&self) -> TaskConfig
Get the task configuration that controls execution behaviour.
Defaults to TaskConfig::minimal() (no retries, no timeout). Override to
attach a circuit-breaker or per-attempt timeout if needed.
Sourcefn name(&self) -> Cow<'static, str>
fn name(&self) -> Cow<'static, str>
Human-readable identifier for this poller, reported to WorkflowObserver hooks.
Defaults to std::any::type_name of the implementing type. Override for a
stable, friendly name.
Sourcefn on_poll_error(&self) -> PollErrorPolicy
fn on_poll_error(&self) -> PollErrorPolicy
Policy for handling errors returned by poll.
Defaults to PollErrorPolicy::FailFast — the first error stops the loop.
Override to tolerate transient errors:
use cano::prelude::*;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Step { Wait, Done }
struct ResilientPoller;
#[task::poll]
impl PollTask<Step> for ResilientPoller {
fn on_poll_error(&self) -> PollErrorPolicy {
PollErrorPolicy::RetryOnError { max_errors: 3 }
}
async fn poll(&self, _res: &Resources) -> Result<PollOutcome<Step>, CanoError> {
Ok(PollOutcome::Ready(TaskResult::Single(Step::Done)))
}
}Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".