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