Skip to content

docs: Clarify actor execution order guarantees in Store#10

Merged
takeshishimada merged 2 commits intomainfrom
docs/clarify-actor-execution-order
Oct 30, 2025
Merged

docs: Clarify actor execution order guarantees in Store#10
takeshishimada merged 2 commits intomainfrom
docs/clarify-actor-execution-order

Conversation

@takeshishimada
Copy link
Copy Markdown
Contributor

Summary

Fix misleading documentation that claimed actions are processed "sequentially" in Store. Per SE-0306, Swift actors (including MainActor) do NOT guarantee FIFO ordering - the runtime uses priority-based scheduling.

Problem

The current documentation states:

Actions are processed sequentially on the MainActor.

This is misleading. While actions execute on MainActor (ensuring thread-safety), multiple send() calls without await may execute in any order due to Swift's priority-based task scheduling.

Changes

  • ✅ Replace "Sequential Processing" section with accurate "MainActor Execution and Task Ordering"
  • ✅ Add explicit reference to SE-0306 with direct quote from the proposal
  • ✅ Add Warning about non-guaranteed execution order
  • ✅ Provide correct usage examples for guaranteed sequential execution using await
  • ✅ Add implementation comments explaining task ordering behavior
  • ✅ Update processAction() documentation for clarity

Technical Details

SE-0306 Quote:

"Tasks awaiting an actor are not guaranteed to be run in the same order they originally awaited that actor."

Before:

store.send(.action1)
store.send(.action2)  // Will wait for action1? ❌ NO!

After (Correct Documentation):

// ⚠️ Order NOT guaranteed
store.send(.action1)
store.send(.action2)

// ✅ Guaranteed sequential execution
await store.send(.action1).value
await store.send(.action2).value

Impact

  • No behavioral changes - only documentation/comments
  • All tests pass (255 tests)
  • SwiftLint clean
  • Helps developers understand actual runtime behavior and use correct patterns

Test Plan

  • Build succeeds
  • All unit tests pass
  • SwiftLint validation passes
  • Documentation is technically accurate per SE-0306

🤖 Generated with Claude Code

Fix misleading documentation that claimed actions are processed
"sequentially". Per SE-0306, Swift actors (including MainActor) do NOT
guarantee FIFO ordering - the runtime uses priority-based scheduling.

Changes:
- Replace "Sequential Processing" section with accurate description
- Add explicit reference to SE-0306 with direct quote
- Add Warning about non-guaranteed execution order
- Provide correct usage examples for guaranteed sequential execution
- Add implementation comments explaining task ordering behavior
- Update processAction() documentation for clarity

The Store now correctly documents that multiple fire-and-forget send()
calls may execute in any order, and users must explicitly await for
guaranteed sequential execution.

Reference: https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 30, 2025
@takeshishimada takeshishimada self-assigned this Oct 30, 2025
@takeshishimada takeshishimada merged commit 397afbc into main Oct 30, 2025
8 checks passed
@takeshishimada takeshishimada deleted the docs/clarify-actor-execution-order branch October 31, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant