Skip to main content

temporalio_workflow/
lib.rs

1#![warn(missing_docs)]
2
3//! Temporal workflow authoring APIs and runtime glue.
4
5extern crate self as temporalio_workflow;
6
7pub use temporalio_common_wasm as common;
8pub use temporalio_macros::{
9    init, query, run, signal, update, update_validator, workflow, workflow_methods,
10};
11
12#[doc(hidden)]
13pub mod __private {
14    pub use futures_util;
15}
16
17#[doc(hidden)]
18pub mod component;
19#[doc(hidden)]
20pub mod runtime;
21mod workflow_context;
22pub mod workflows;
23
24#[doc(hidden)]
25pub use runtime::model::{CancellableID, UnblockEvent};
26pub use runtime::model::{TimerResult, WorkflowResult, WorkflowTermination};
27#[doc(hidden)]
28pub use runtime::{SdkWakeGuard, is_sdk_wake};
29pub use temporalio_common_wasm::error::{
30    ActivityExecutionError, ChildWorkflowExecutionError, ChildWorkflowStartError,
31    WorkflowSignalError,
32};
33pub use workflow_context::{
34    ActivityCloseTimeouts, ActivityOptions, BaseWorkflowContext, CancellableFuture,
35    ChildWorkflowOptions, ContinueAsNewOptions, ContinueAsNewVersioningBehavior,
36    ExternalWorkflowHandle, LocalActivityOptions, NexusOperationOptions, ParentWorkflowInfo,
37    RootWorkflowInfo, Signal, SignalData, StartChildWorkflowExecutionFailedCause,
38    StartedChildWorkflow, SyncWorkflowContext, TimerOptions, WorkflowContext, WorkflowContextView,
39};
40pub use workflows::{join, join_all, select};
41
42#[macro_export]
43#[doc(hidden)]
44macro_rules! __temporal_select {
45    ($($tokens:tt)*) => {
46        $crate::__private::futures_util::select_biased! { $($tokens)* }
47    };
48}
49
50#[macro_export]
51#[doc(hidden)]
52macro_rules! __temporal_join {
53    ($($tokens:tt)*) => {
54        $crate::__private::futures_util::join!($($tokens)*)
55    };
56}
57
58#[macro_export]
59#[doc(hidden)]
60macro_rules! __temporalio_export_workflow_component {
61    ($export_type:ident) => {
62        $crate::component::__wit_export!(
63            $export_type with_types_in $crate::component::bindings
64        );
65    };
66}
67
68#[macro_export]
69/// Export one or more workflow implementations as a component-model workflow module.
70macro_rules! export_workflow_module {
71    ([$($workflow:ty),+ $(,)?]) => {
72        const _: () = {
73            struct __TemporalWorkflowModule;
74
75            impl ::temporalio_workflow::component::StaticWorkflowComponent for __TemporalWorkflowModule {
76                fn list_workflows(
77                ) -> ::std::vec::Vec<::temporalio_workflow::runtime::types::WorkflowDefinitionDescriptor> {
78                    ::std::vec![$(<$workflow as ::temporalio_workflow::runtime::entry::WorkflowImplementation>::definition()),*]
79                }
80
81                fn instantiate_workflow(
82                    workflow_type: &str,
83                    init: ::temporalio_workflow::runtime::types::WorkflowInit,
84                    host: ::std::rc::Rc<dyn ::temporalio_workflow::runtime::host::WorkflowHost>,
85                ) -> ::std::result::Result<
86                    ::std::boxed::Box<dyn ::temporalio_workflow::runtime::guest::WorkflowInstance>,
87                    ::temporalio_workflow::runtime::types::WorkflowFailure,
88                > {
89                    match workflow_type {
90                        $(
91                            name if name == <$workflow as ::temporalio_workflow::runtime::entry::WorkflowImplementation>::name() => {
92                                ::temporalio_workflow::component::instantiate_component_workflow::<$workflow>(init, host)
93                            }
94                        )*
95                        _ => Err(::std::boxed::Box::new(
96                            ::temporalio_workflow::common::protos::temporal::api::failure::v1::Failure {
97                                message: ::std::format!(
98                                    "No workflow named '{}' exported by this component",
99                                    workflow_type
100                                ),
101                                ..::std::default::Default::default()
102                            },
103                        )),
104                    }
105                }
106            }
107
108            type __TemporalWorkflowComponentExport =
109                ::temporalio_workflow::component::ExportedComponent<__TemporalWorkflowModule>;
110
111            ::temporalio_workflow::__temporalio_export_workflow_component!(
112                __TemporalWorkflowComponentExport
113            );
114        };
115    };
116}