---
title: "whenLocal(_:)"
framework: distributed
role: symbol
role_heading: Instance Method
path: "distributed/distributedactor/whenlocal(_:)"
---

# whenLocal(_:)

Executes the passed ‘body’ only when the distributed actor is local instance.

## Declaration

```swift
nonisolated func whenLocal<T, E>(_ body: @Sendable (isolated Self) async throws(E) -> T) async throws(E) -> T? where T : Sendable, E : Error
```

## Discussion

Discussion The Self passed to the body closure is isolated, meaning that the closure can be used to call non-distributed functions, or even access actor state. When the actor is remote, the closure won’t be executed and this function will return nil.
