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.
import { Workflow } from '@node-ts/bus-core'
​
export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
configureWorkflow (
mapper: WorkflowMapper<FulfilmentWorkflowState, FulfilmentWorkflow>
): void {
mapper
.withState(FulfilmentWorkflowState)
// ...
.when(ReceiptSent, 'complete')
}
async complete (_: ReceiptSent) {
return this.completeWorkflow()
}
}
Final changes to the workflow state can be passed in as a parameter to completeWorkflow() if desired
​
export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
configureWorkflow (
mapper: WorkflowMapper<FulfilmentWorkflowState, FulfilmentWorkflow>
): void {
mapper
.withState(FulfilmentWorkflowState)
// ...
.when(ReceiptSent, 'complete')
}
async complete (_: ReceiptSent) {
return this.completeWorkflow({ status: 'complete' })
}
}
Last modified 11mo ago
Copy link