use dex_sdk::{
Context, Flow, HandlerResult, PersistenceSchema, Step, StepDecision, StepList, Stream,
};
#[derive(Clone)]
pub(crate) struct StreamTestWorkflow {
pub(crate) progress: Stream<String>,
start: StreamTestStep,
}
impl StreamTestWorkflow {
pub(crate) fn new() -> Self {
let progress = Stream::new("stream-test-progress", 1 << 20);
Self {
progress: progress.clone(),
start: StreamTestStep { progress },
}
}
}
impl Flow for StreamTestWorkflow {
type StartInput = ();
fn steps(&self) -> StepList<'_, Self::StartInput> {
StepList::start(&self.start)
}
fn persistence(&self) -> PersistenceSchema {
PersistenceSchema::new().stream(&self.progress)
}
}
#[derive(Clone)]
struct StreamTestStep {
progress: Stream<String>,
}
impl Step for StreamTestStep {
type Input = ();
fn execute(&self, context: &mut Context, _input: ()) -> HandlerResult<StepDecision> {
self.progress.write(context, "step-progress".to_string())?;
Ok(StepDecision::graceful_complete(()))
}
}