Skip to content

Commit 11b6bd0

Browse files
committed
better example
1 parent 1e7e518 commit 11b6bd0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,18 @@ import Swift
9595
/// struct Work: Sendable {}
9696
///
9797
/// actor Worker {
98-
/// var work: Task<Work, Never>?
98+
/// var work: Task<Void, Never>?
99+
/// var result: Work?
99100
///
100101
/// deinit {
101-
///
102102
/// print("deinit")
103103
/// }
104104
///
105105
/// func start() {
106106
/// work = Task {
107-
/// return Work()
107+
/// try? await Task.sleep(for: .seconds(3))
108+
/// self.work = Work() // we captured self
109+
/// // but as the task completes, this reference is released
108110
/// }
109111
/// }
110112
/// }

0 commit comments

Comments
 (0)