Contents

whenLocal(_:)

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

Declaration

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

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.