# Wait

Define a Wait state in the state machine.

A Wait state can be used to delay execution of the state machine for a while.

Extends: Construct › State › Wait
Implements: IChainable, INextable, IConstruct, IDependable

- Source: [`aws-stepfunctions/lib/states/wait.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-stepfunctions/lib/states/wait.ts#L87)
- Type last changed: v2.178.0 · 6 Feb 2025

## Example

```ts
const convertToSeconds = new tasks.EvaluateExpression(this, 'Convert to seconds', {
  expression: '$.waitMilliseconds / 1000',
  resultPath: '$.waitSeconds',
});

const createMessage = new tasks.EvaluateExpression(this, 'Create message', {
  // Note: this is a string inside a string.
  expression: '`Now waiting ${$.waitSeconds} seconds...`',
  runtime: lambda.Runtime.NODEJS_LATEST,
  resultPath: '$.message',
});

const publishMessage = new tasks.SnsPublish(this, 'Publish message', {
  topic: new sns.Topic(this, 'cool-topic'),
  message: sfn.TaskInput.fromJsonPathAt('$.message'),
  resultPath: '$.sns',
});

const wait = new sfn.Wait(this, 'Wait', {
  time: sfn.WaitTime.secondsPath('$.waitSeconds'),
});

new sfn.StateMachine(this, 'StateMachine', {
  definition: convertToSeconds
    .next(createMessage)
    .next(publishMessage)
    .next(wait),
});
```

## Initializer

```ts
new Wait(scope: Construct, id: string, props: WaitProps)
```

## Construct Props

- `assign`: { [key: string]: any } — Workflow variables to store in this step.

  **Default:** Not assign variables

  Using workflow variables, you can store data in a step and retrieve that data in future steps.

- `comment`: string — A comment describing this state.

  **Default:** No comment

- `queryLanguage`: [QueryLanguage](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.QueryLanguage.html) = JSONPath — The name of the query language used by the state.

  If the state does not contain a `queryLanguage` field,
  then it will use the query language specified in the top-level `queryLanguage` field.

- `stateName`: string — Optional name for this state.

  **Default:** The construct ID will be used as state name

- `time`: [WaitTime](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.WaitTime.html) (required) — Wait duration.

## Properties

- `endStates`: [INextable](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.INextable.html)[] — Continuable states of this Chainable.

- `id`: string — Descriptive identifier for this chainable.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `startState`: [State](/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.State.html) — First state of this Chainable.

- `stateId`: string — Tokenized string that evaluates to the state's ID.

## Methods

- `addPrefix(x: string): void` — Add a prefix to the stateId of this state.

- `bindToGraph(graph: StateGraph): void` — Register this state as part of the given graph.

  Don't call this. It will be called automatically when you work
  with states normally.

- `filterNextables(states: State[]): INextable[]` (static) — Return only the states that allow chaining from an array of states.

- `findReachableEndStates(start: State, options?: FindStateOptions): State[]` (static) — Find the set of end states states reachable through transitions from the given start state.

- `findReachableStates(start: State, options?: FindStateOptions): State[]` (static) — Find the set of states reachable through transitions from the given start state.

  This does not retrieve states from within sub-graphs, such as states within a Parallel state's branch.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `jsonata(scope: Construct, id: string, props: WaitJsonataProps): Wait // chainable` (static) — Define a Wait state using JSONata in the state machine.

  A Wait state can be used to delay execution of the state machine for a while.

- `jsonPath(scope: Construct, id: string, props: WaitJsonPathProps): Wait // chainable` (static) — Define a Wait state using JSONPath in the state machine.

  A Wait state can be used to delay execution of the state machine for a while.

- `next(next: IChainable): Chain` — Continue normal execution with the given state.

- `prefixStates(root: IConstruct, prefix: string): void` (static) — Add a prefix to the stateId of all States found in a construct tree.

- `toStateJson(topLevelQueryLanguage?: QueryLanguage): json` — Return the Amazon States Language object for this state.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
