Namespace: workflow
This library provides tools required for authoring workflows.
Usage
See the tutorial for writing your first workflow.
Timers
The recommended way of scheduling timers is by using the sleep function. We've replaced setTimeout and
clearTimeout with deterministic versions so these are also usable but have a limitation that they don't play well
with cancellation scopes.
import { sleep } from '@temporalio/workflow';
export async function sleeper(ms = 100): Promise<void> {
await sleep(ms);
console.log('slept');
}
Activities
To schedule Activities, use proxyActivities to obtain an Activity function and call.
Updates, Signals and Queries
Use setHandler to set handlers for Updates, Signals, and Queries.
Update and Signal handlers can be either async or non-async functions. Update handlers may return a value, but signal
handlers may not (return void or Promise<void>). You may use Activities, Timers, child Workflows, etc in Update
and Signal handlers, but this should be done cautiously: for example, note that if you await async operations such as
these in an Update or Signal handler, then you are responsible for ensuring that the workflow does not complete first.
Query handlers may not be async functions, and may not mutate any variables or use Activities, Timers, child Workflows, etc.
Implementation
export const incrementSignal = wf.defineSignal<[number]>('increment');
export const getValueQuery = wf.defineQuery<number>('getValue');
export const incrementAndGetValueUpdate = wf.defineUpdate<number, [number]>('incrementAndGetValue');
export async function counterWorkflow(initialValue: number): Promise<void> {
let count = initialValue;
wf.setHandler(incrementSignal, (arg: number) => {
count += arg;
});
wf.setHandler(getValueQuery, () => count);
wf.setHandler(incrementAndGetValueUpdate, (arg: number): number => {
count += arg;
return count;
});
await wf.condition(() => false);
}
More
Classes
- CancellationScope
- ContinueAsNew
- DeterminismViolationError
- LocalActivityDoBackoff
- Trigger
- WorkflowError
Interfaces
- ActivateInput
- ActivityInput
- CancellationScopeOptions
- ChildWorkflowHandle
- ChildWorkflowOptions
- ConcludeActivationInput
- ContinueAsNewInput
- ContinueAsNewOptions
- DisposeInput
- EnhancedStackTrace
- ExternalWorkflowHandle
- LocalActivityInput
- LoggerSinks
- NexusOperationHandle
- NexusServiceClient
- NexusServiceClientOptions
- ParentWorkflowInfo
- QueryInput
- RootWorkflowInfo
- SignalInput
- SignalWorkflowInput
- SinkCall
- StackTrace
- StackTraceFileLocation
- StackTraceFileSlice
- StackTraceSDKInfo
- StartChildWorkflowExecutionInput
- StartNexusOperationInput
- StartNexusOperationOptions
- StartNexusOperationOutput
- TimerInput
- TimerOptions
- UnsafeWorkflowInfo
- UpdateInput
- WorkflowExecuteInput
- WorkflowInboundCallsInterceptor
- WorkflowInfo
- WorkflowInterceptors
- WorkflowInternalsInterceptor
- WorkflowOutboundCallsInterceptor
References
ActivityCancellationType
Re-exports ActivityCancellationType
ActivityFailure
Re-exports ActivityFailure
ActivityFunction
Re-exports ActivityFunction
ActivityInterface
Re-exports ActivityInterface
ActivityOptions
Re-exports ActivityOptions
ApplicationFailure
Re-exports ApplicationFailure
BaseWorkflowHandle
Re-exports BaseWorkflowHandle
BaseWorkflowOptions
Re-exports BaseWorkflowOptions
CancelledFailure
Re-exports CancelledFailure
ChildWorkflowFailure
Re-exports ChildWorkflowFailure
CommonWorkflowOptions
Re-exports CommonWorkflowOptions
CompleteAsyncError
Re-exports CompleteAsyncError
Headers
Re-exports Headers
IllegalStateError
Re-exports IllegalStateError
NamespaceNotFoundError
Re-exports NamespaceNotFoundError
Next
Re-exports Next
Payload
Re-exports Payload
PayloadConverter
Re-exports PayloadConverter
PayloadConverterError
Re-exports PayloadConverterError
QueryDefinition
Re-exports QueryDefinition
RetryPolicy
Re-exports RetryPolicy
SearchAttributeValue
Re-exports SearchAttributeValue
SearchAttributes
Re-exports SearchAttributes
ServerFailure
Re-exports ServerFailure
SignalDefinition
Re-exports SignalDefinition
TemporalFailure
Re-exports TemporalFailure
TerminatedFailure
Re-exports TerminatedFailure
TimeoutFailure
Re-exports TimeoutFailure
UntypedActivities
Re-exports UntypedActivities
ValueError
Re-exports ValueError
WithWorkflowArgs
Re-exports WithWorkflowArgs
Workflow
Re-exports Workflow
WorkflowDurationOptions
Re-exports WorkflowDurationOptions
WorkflowIdConflictPolicy
Re-exports WorkflowIdConflictPolicy
WorkflowIdReusePolicy
Re-exports WorkflowIdReusePolicy
WorkflowNotFoundError
Re-exports WorkflowNotFoundError
WorkflowQueryType
Re-exports WorkflowQueryType
WorkflowResultType
Re-exports WorkflowResultType
WorkflowReturnType
Re-exports WorkflowReturnType
WorkflowSignalType
Re-exports WorkflowSignalType