Repository navigation
Document task-local, priority, and cancellation behavior - #93
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/2.0-7-fifo-queue-turns #93 +/- ##
===============================================================
Coverage 100.00% 100.00%
===============================================================
Files 12 12
Lines 1865 1876 +11
===============================================================
+ Hits 1865 1876 +11
🚀 New features to boost your workflow:
|
0740990 to
405ad63
Compare
fb7247d to
559a989
Compare
559a989 to
02bd142
Compare
|
Build Xcode (iOS,watchOS) failed on The log has no test output at all, so the code on this branch had no part in it. It's a simulator failure on the Generated by Claude Code |
|
Correction: the CodeQL Swift failure I reported here is fixed by Generated by Claude Code |
- Rewrite the `Task(on:)` documentation to describe what each initializer actually does: the operation's isolation, its ordering, that it inherits the caller's task-local values and priority, that awaiting it escalates its priority, and that cancelling a pending task does not remove it from its queue. - Document that a `FIFOQueue`'s priority is a floor. - Add the `priority:` parameter that the two `CancellableQueue<FIFOQueue>` initializers without `isolatedTo:` were missing. - Fix the README's `CancellableQueue` sample, which did not compile: it used `try` in a nonthrowing task and called an async method without `await`. - Remove references to `enqueue` and `enqueueAndWait`, and to the queue's own task, none of which exist anymore. Rewrite the README so that it is easy to follow, in the voice and vocabulary of the Concurrency chapter of The Swift Programming Language. It now opens with a short guide to choosing a queue, gives each queue its own section around the existing examples, and describes behavior in the guide's terms (tasks, actors, suspension points, task priority, task-local values, and cooperative cancellation) instead of terms the library made up, such as nonisolated and isolated contexts, adopted execution contexts, and FIFO order. It corrects the claim that `MainActor.queue` runs tasks in FIFO order: it is an `ActorQueue`, so the next task can start once a task suspends. It also points the guide links at sections that still exist. The installation section keeps its wording, with the version raised to 2.0.0; what changed in 2.0 and what to do belongs in the release notes. Apart from the `CancellableQueue` fix, the examples' code is unchanged except for comments. Describe the queues in the same plain terms in the public doc comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
02bd142 to
ab0abd7
Compare
Summary
Task(on:)doc comment now describes what the initializer does:FIFOQueue) or has finished or suspended (ActorQueue).adoptExecutionContext(of:), andcancelTasks()in the same plain terms as the README. Each comment uses one set of words throughout: "tasks enqueued before it", "finished", and "the code that enqueues it".FIFOQueue's priority is a floor.priority:parameter that the twoCancellableQueue<FIFOQueue>initializers withoutisolatedTo:were missing. Like everyCancellableQueueinitializer since Cancel tasks that are still being enqueued when cancelTasks() is called #90, they create their task throughtrackTask(performing:createdBy:).CancellableQueuesample, which did not compile. It usedtryin a non-throwing task and called an async method withoutawait. All five README@Testsamples now compile, and all butactorTaskOrdering, which shows the problem the queues solve, pass.enqueue,enqueueAndWait, and the queue's own task, none of which exist anymore.FIFOQueue(priority: .medium)restores the old floor;ActorQueuecallers should passpriority:when enqueuing important work from low-priority code.name:initializers are removed.README
Task(on:)compares withTask.init. It explains operation in one line where the word first appears.MainActor.queueruns tasks in FIFO order. It is anActorQueue, so the next task can start once a task suspends.#ID645and#ID639guide links.Package.swiftalready states the Swift and platform requirements.ActorQueuesection.CancellableQueuesample fix above, keeps the examples' code and changes only comments.CancellableQueue(underlyingQueue: FIFOQueue())snippet) compiles and runs with Swift 6.4.2 against this commit, with stand-ins forUIImage,performWork(), and the two placeholder function bodies.actorTaskOrderingstill fails often, as it should. The inlineawait Task(on: queue) { myself in myself.count }.valueline compiles and returns the count inside theActorQueueexample'sCounter, from both an isolated and anonisolatedmethod.Tests
task_fifoQueue_withPriority_executesAtThatPrioritychecks, for the throwing and non-throwing initializers, that the newpriority:parameter sets the priority the task runs at. It enqueues a.lowtask from a.hightask and reads the priority the task reports through a stream, without awaiting the task, so awaiting cannot escalate it.Series
PR 9 of 10. It is stacked on #92.
Validation
Each commit in the series was validated on its own, on Linux with Swift 6.4.2, from a
git archivecopy:-warnings-as-errors, andswiftformat --lintis clean.ci.ymlunderbash -e, pass, including the atomic-counter check. No line inSourcesorTestsreads zero in the CI run.Synchronization.Mutexeven in trivially correct code, so the TSan runs replaceMutexwith a pthread-based lock that TSan understands.Nothing was run on Apple platforms. CI is the first run there.
Review checklist
Left for code review because no test can force them:
turn.begin(). This PR rewrites the doc comments around everyTask(on:)initializer; each must still await its turn before running its operation. Onlymain's ordering loops cover a missingawait turn.begin().🤖 Generated with Claude Code
https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM