---
title: "addScheduledHandler(_:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlcommandbuffer/addscheduledhandler(_:)"
---

# addScheduledHandler(_:)

Registers a completion handler the GPU device calls immediately after it schedules the command buffer to run on the GPU.

## Declaration

```swift
func addScheduledHandler(_ block: @escaping MTLCommandBufferHandler)
```

## Parameters

- `block`: A Swift closure or an Objective-C block that Metal calls after it schedules the command buffer to run on the GPU.

## Mentioned in

Setting up a command structure

## Discussion

Discussion You can register one or more scheduling completion handlers for the same command buffer. The GPU device’s driver (on the CPU) calls the completion handlers after it finishes scheduling the command buffer to run on the GPU. important: You can only call this method before calling the command buffer’s commit() method. The GPU device schedules each command buffer — along with tasks from other command buffers — after it identifies the command buffer’s dependencies. At that time, the GPU device sets the command buffer’s status to MTLCommandBufferStatus.scheduled and calls your completion handler. note: The command buffer’s status property may be equal to another (larger) value by the time your completion handler runs, including MTLCommandBufferStatus.completed. You can use the command buffer’s kernelEndTime and kernelStartTime properties to calculate how much time the CPU spends scheduling the command buffer.

## See Also

### Registering state change handlers

- [addCompletedHandler(_:)](metal/mtlcommandbuffer/addcompletedhandler(_:).md)
- [MTLCommandBufferHandler](metal/mtlcommandbufferhandler.md)
