You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Guide.docc/IncrementalAdoption.md
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -508,3 +508,21 @@ await withTaskGroup(of: Something.self) { group in
508
508
}
509
509
}
510
510
```
511
+
512
+
If the "work" task involves long-running synchronous code it may make sense to voluntarily suspend the task and allow other tasks to execute:
513
+
514
+
```swift
515
+
structWork {
516
+
let dependency: Dependency
517
+
funcwork() async {
518
+
await dependency.fetch()
519
+
// execute part of long running synchronous code
520
+
await Task.yield() // explicitly insert a suspension point
521
+
// continue long running synchronous execution
522
+
}
523
+
}
524
+
```
525
+
526
+
Introducing an explicit suspension point helps Swift balance between making progress on this task, and letting other tasks in your program make progress on their work.
527
+
However, if this task has the highest-priority in the system, the executor immediately resumes execution of the same task.
528
+
Therefore an explicit suspension point isn’t necessarily a way to avoid resource starvation.
0 commit comments