the.bay.news

Lifetime of a Sendable ~Copyable captured by a Task

Swift Forums
Lifetime of a Sendable ~Copyable captured by a Task
When a Sendable ~Copyable value (e.g.: a Atomic) is captured by a Task closure, how does the compiler know the lifetime of this value and where to insert the deinit call? For example: let task = { let v = Atomic<Int>(42) let task = Task.detached { try await Task.sleep(for: .seconds(2)) print("value: \(v.load(ordering: .relaxed))") } v.store(43, ordering: .relaxed) return task }() _ = try await task.value This code works fine, but how does it correctly keep...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.