# 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.

```typescript
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

```typescript

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' })
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bus.node-ts.com/guide/workflows/completing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
