Skip to content

Latest commit

 

History

History
28 lines (18 loc) · 680 Bytes

Sendability.md

File metadata and controls

28 lines (18 loc) · 680 Bytes

Sendability

Passing data around across isolation domains means you the types to conform to Sendable.

Non-Sendable Arguments

You need to pass some non-Sendable arguments into a function in a different isolution domain.

func myAsyncFunction(_ nonSendable: NonSendable) async {
}

let nonSendable = NonSendable()

// this produces a warning
await myAsyncFunction(nonSendable)

Solution #1: create data in a closure

Assumption: the definition is under your control.

func myAsyncFunction(_ nonSendable: @Sendable () -> NonSendable) async {
}

await myAsyncFunction({ NonSendable() })