dex_sdk/stop_flow_options.rs
1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Super Durable Source License 1.0.
4// You may not use this file except in compliance with the License.
5// See the LICENSE file in the repository root.
6//
7// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
8
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
10pub(crate) enum StopType {
11 Cancel,
12 Terminate,
13 Fail,
14}
15
16#[derive(Clone, Debug, Eq, PartialEq)]
17/// Selects how [`crate::Client::stop_flow`] ends an active Flow.
18///
19/// Construct a value with [`Self::cancel`], [`Self::terminate`], or [`Self::fail`], then optionally
20/// attach an operator-facing reason.
21pub struct StopFlowOptions {
22 pub(crate) stop_type: StopType,
23 pub(crate) reason: Option<String>,
24}
25
26impl StopFlowOptions {
27 fn new(stop_type: StopType) -> Self {
28 Self {
29 stop_type,
30 reason: None,
31 }
32 }
33
34 /// Requests cooperative cancellation so application cleanup can run.
35 pub fn cancel() -> Self {
36 Self::new(StopType::Cancel)
37 }
38
39 /// Terminates the Flow immediately without cooperative cleanup.
40 pub fn terminate() -> Self {
41 Self::new(StopType::Terminate)
42 }
43
44 /// Marks the Flow failed with the reason set by [`Self::reason`].
45 pub fn fail() -> Self {
46 Self::new(StopType::Fail)
47 }
48
49 /// Attaches a reason recorded with the stop operation.
50 pub fn reason(mut self, value: impl Into<String>) -> Self {
51 self.reason = Some(value.into());
52 self
53 }
54}