---
title: "wait(for:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlresourcestatecommandencoder/wait(for:)"
---

# wait(for:)

Encodes a command that instructs the GPU to pause before starting the resource state commands until another pass updates a fence.

## Declaration

```swift
func wait(for fence: any MTLFence)
```

```swift
optional func wait(for fence: any MTLFence)
```

## Parameters

- `fence`: An doc://com.apple.metal/documentation/Metal/MTLFence instance to pause execution on until updated.

## Discussion

Discussion Fences maintain order to prevent GPU data hazards as the GPU runs various passes within the same command queue. The encoded resource state commands wait for a pass to update fence before running. The GPU driver evaluates the fences that apply to the pass and the commands that depend on those fences when your app commits the enclosing MTLCommandBuffer.

## See Also

### Performing fence operations

- [update(_:)](metal/mtlresourcestatecommandencoder/update(_:).md)
