---
title: "withSerialExecutor(_:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/actor/withserialexecutor(_:)-4ucv5"
---

# withSerialExecutor(_:)

Perform an operation with the actor’s SerialExecutor.

## Declaration

```swift
nonisolated func withSerialExecutor<T, E>(_ operation: (any SerialExecutor) throws(E) -> T) throws(E) -> T where E : Error, T : ~Copyable
```

## Discussion

Discussion This converts the actor’s unownedExecutor to a SerialExecutor while retaining the actor for the duration of the operation. This is to ensure the lifetime of the executor while performing the operation.
