---
url: https://node-ts.github.io/bus/guide/workflows/completing.md
description: Mark a workflow as complete so it handles no more messages.
---

# Completing

A workflow that has finished its work should be marked as complete, after which no more messages are dispatched to it. This page shows how.

Return `ctx.complete()` from a function workflow handler, or `this.completeWorkflow()` from a class workflow handler. Either can be given final changes to the state, which are saved with it.

::: code-group

```ts \[Functions]
export const fulfilmentWorkflow = defineWorkflow(FulfilmentWorkflowState)
  .startedBy(ItemPurchased, ({ itemId, customerId }) => ({
    itemId,
    customerId
  }))
  // Complete the workflow, saving one last change to its state
  .when(ReceiptEmailed, (_event, _state, ctx) =>
    ctx.complete({ status: 'complete' })
  )
```

```ts \[Class]
export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
  configureWorkflow(
    mapper: WorkflowMapper<FulfilmentWorkflowState, FulfilmentWorkflow>
  ): void {
    mapper
      .withState(FulfilmentWorkflowState)
      .startedBy(ItemPurchased, 'start')
      .when(ReceiptEmailed, 'complete')
  }

  start({ itemId, customerId }: ItemPurchased) {
    return { itemId, customerId }
  }

  complete() {
    // Complete the workflow, saving one last change to its state
    return this.completeWorkflow({ status: 'complete' })
  }
}
```

:::

The completed state stays in the persistence, with its `$status` set to `complete`, but isn't found by later messages.

## See also

* [Example](/guide/workflows/example), a complete workflow
* [State](/guide/workflows/state)
