Skip to main content

temporalio_workflow/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(missing_docs)]
3
4//! Temporal workflow authoring APIs and runtime glue.
5
6extern crate self as temporalio_workflow;
7
8pub use temporalio_common_wasm as common;
9pub use temporalio_macros::{
10    init, query, run, signal, update, update_validator, workflow, workflow_methods,
11};
12
13#[doc(hidden)]
14pub mod __private {
15    pub use futures_util;
16}
17
18mod cancellation;
19#[doc(hidden)]
20pub mod component;
21#[doc(hidden)]
22pub mod runtime;
23mod workflow_context;
24pub mod workflow_interceptors;
25pub mod workflows;
26
27pub use cancellation::{WorkflowCancellationError, WorkflowCancellationToken};
28#[doc(hidden)]
29pub use runtime::model::{CancellableID, UnblockEvent};
30pub use runtime::model::{TimerResult, WorkflowResult, WorkflowTermination};
31#[doc(hidden)]
32pub use runtime::{SdkWakeGuard, is_sdk_wake};
33pub use temporalio_common_wasm::{
34    ActivityCloseTimeouts, Memo, MemoValue, MemoValues, RetryPolicy,
35    error::{
36        ActivityExecutionError, ChildWorkflowExecutionError, ChildWorkflowStartError, RetryState,
37        TimeoutType, WorkflowSignalError,
38    },
39};
40pub use workflow_context::{
41    ActivityCancellationType, ActivityOptions, BaseWorkflowContext, CancellableFuture,
42    CancellableFutureWithReason, ChildWorkflowCancellationType, ChildWorkflowOptions,
43    ContinueAsNewOptions, ExternalWorkflowHandle, LocalActivityOptions, NamespacedWorkflowInfo,
44    ParentClosePolicy, SignalWorkflowOptions, StartChildWorkflowExecutionFailedCause,
45    StartChildWorkflowOutput, StartedChildWorkflow, SyncWorkflowContext, TimerOptions,
46    VersioningIntent, WaitConditionOptions, WorkflowContext, WorkflowContextView,
47    WorkflowIdReusePolicy, WorkflowRandomStream, WorkflowRandomValue,
48};
49#[cfg(feature = "experimental")]
50pub use workflow_context::{
51    ContinueAsNewVersioningBehavior, NexusOperationCancellationType, NexusOperationOptions,
52    PatchActivationCallback, PatchActivationInput, StartedNexusOperation,
53};
54#[doc(hidden)]
55pub use workflow_context::{
56    PatchActivationCallback as InternalPatchActivationCallback, PatchActivationCaller,
57};
58pub use workflows::{join, join_all, select};
59
60#[macro_export]
61#[doc(hidden)]
62macro_rules! __temporal_select {
63    ($($tokens:tt)*) => {
64        $crate::__private::futures_util::select_biased! { $($tokens)* }
65    };
66}
67
68#[macro_export]
69#[doc(hidden)]
70macro_rules! __temporal_join {
71    ($($tokens:tt)*) => {
72        $crate::__private::futures_util::join!($($tokens)*)
73    };
74}
75
76#[macro_export]
77#[doc(hidden)]
78macro_rules! __temporalio_export_workflow_component {
79    ($export_type:ident) => {
80        $crate::component::__wit_export!(
81            $export_type with_types_in $crate::component::bindings
82        );
83    };
84}
85
86#[macro_export]
87/// Export one or more workflow implementations as a component-model workflow module.
88///
89/// Component-side workflow interceptor constructors can be supplied with
90/// `interceptor_constructors = [constructor]`. Each constructor receives a read-only workflow
91/// context and is invoked for every workflow instance.
92macro_rules! export_workflow_module {
93    ([$($workflow:ty),+ $(,)?]) => {
94        ::temporalio_workflow::export_workflow_module!(
95            [$($workflow),+],
96            interceptor_constructors = [],
97        );
98    };
99    ([$($workflow:ty),+ $(,)?], interceptor_constructors = [$($constructor:expr),* $(,)?] $(,)?) => {
100        const _: () = {
101            struct __TemporalWorkflowModule;
102
103            fn __temporal_workflow_interceptor_constructors() -> ::std::vec::Vec<
104                ::temporalio_workflow::workflow_interceptors::WorkflowInterceptorConstructor,
105            > {
106                ::std::vec![
107                    $(
108                        ::temporalio_workflow::workflow_interceptors::WorkflowInterceptorConstructor::new(
109                            $constructor,
110                        )
111                    ),*
112                ]
113            }
114
115            impl ::temporalio_workflow::component::StaticWorkflowComponent for __TemporalWorkflowModule {
116                fn list_workflows(
117                ) -> ::std::vec::Vec<::temporalio_workflow::runtime::types::WorkflowDefinitionDescriptor> {
118                    ::std::vec![$(<$workflow as ::temporalio_workflow::runtime::entry::WorkflowImplementation>::definition()),*]
119                }
120
121                fn instantiate_workflow(
122                    workflow_type: &str,
123                    init: ::temporalio_workflow::runtime::types::WorkflowInit,
124                    host: ::std::rc::Rc<dyn ::temporalio_workflow::runtime::host::WorkflowHost>,
125                ) -> ::std::result::Result<
126                    ::std::boxed::Box<dyn ::temporalio_workflow::runtime::guest::WorkflowInstance>,
127                    ::temporalio_workflow::runtime::types::WorkflowFailure,
128                > {
129                    match workflow_type {
130                        $(
131                            name if name == <$workflow as ::temporalio_workflow::runtime::entry::WorkflowImplementation>::name() => {
132                                ::temporalio_workflow::component::instantiate_component_workflow_with_interceptor_constructors::<$workflow>(
133                                    init,
134                                    host,
135                                    __temporal_workflow_interceptor_constructors(),
136                                )
137                            }
138                        )*
139                        _ => Err(::std::boxed::Box::new(
140                            ::temporalio_workflow::common::protos::temporal::api::failure::v1::Failure {
141                                message: ::std::format!(
142                                    "No workflow named '{}' exported by this component",
143                                    workflow_type
144                                ),
145                                ..::std::default::Default::default()
146                            },
147                        )),
148                    }
149                }
150            }
151
152            type __TemporalWorkflowComponentExport =
153                ::temporalio_workflow::component::ExportedComponent<__TemporalWorkflowModule>;
154
155            ::temporalio_workflow::__temporalio_export_workflow_component!(
156                __TemporalWorkflowComponentExport
157            );
158        };
159    };
160}