Completing
A workflow is completed by returning this.completeWorkflow() from within a handler. This will set the state of the workflow to completed and will no longer be activated by any incoming messages.
1
import { Workflow } from '@node-ts/bus-core'
2
​
3
export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
4
configureWorkflow (
5
mapper: WorkflowMapper<FulfilmentWorkflowState, FulfilmentWorkflow>
6
): void {
7
mapper
8
.withState(FulfilmentWorkflowState)
9
// ...
10
.when(ReceiptSent, 'complete')
11
}
12
13
async complete (_: ReceiptSent) {
14
return this.completeWorkflow()
15
}
16
}
Copied!
Final changes to the workflow state can be passed in as a parameter to completeWorkflow() if desired
1
​
2
export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
3
configureWorkflow (
4
mapper: WorkflowMapper<FulfilmentWorkflowState, FulfilmentWorkflow>
5
): void {
6
mapper
7
.withState(FulfilmentWorkflowState)
8
// ...
9
.when(ReceiptSent, 'complete')
10
}
11
12
async complete (_: ReceiptSent) {
13
return this.completeWorkflow({ status: 'complete' })
14
}
15
}
Copied!
Last modified 7mo ago
Copy link