-
-
Notifications
You must be signed in to change notification settings - Fork 14
Add consistent examples to README #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| func test_mainActor_taskOrdering() async { | ||
| var counter = 0 | ||
| func testMainActorTaskOrdering() async { | ||
| actor Counter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need a Counter type in this example but the below examples do need it. For the sake of consistency with the below additions I made this example test a dash more complicated.
| This task begins execution once the above one-second sleep completes. | ||
| */ | ||
| } | ||
| Task { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Task was meant to show that we were entering an async context, but I'm realizing now that the inclusion of the Task is more confusing than not. Nothing within the Task closure changed – I just removed the Task enclosure. I did the same thing further down as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. The reader can infer from the await below that we're in an asynchronous context.
| } | ||
| await queue.await { } | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd explain better how the ActorQueue and FIFOQueue differ in the above example test, but I'm wary of trying to communicate too many ideas at once.
Codecov Report
@@ Coverage Diff @@
## main #8 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 703 703
=========================================
Hits 703 703 |
| This task begins execution once the above one-second sleep completes. | ||
| */ | ||
| } | ||
| Task { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. The reader can infer from the await below that we're in an asynchronous context.
| XCTAssertEqual(incrementedCount, iteration) // always succeeds | ||
| } | ||
| } | ||
| await queue.await { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe clarify with a comment that we're ensuring all tasks complete before we end the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this in #9 which builds on top of this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| XCTAssertEqual(incrementedCount, iteration) // always succeeds | ||
| } | ||
| } | ||
| await queue.await { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we also clarify the purpose of this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this in #9 which builds on top of this change.
This PR gets each section of the README re-visiting the same ordering test to make explicit how these types solve the problem statement in the
Task Ordering and Swift Concurrencysection of the README.There's still room to improve the explanation of these types, but we're making progress here.