-
-
Notifications
You must be signed in to change notification settings - Fork 14
Make ActorQueue's tasks isolated to an actor's context #7
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
cf7c00b to
15d770f
Compare
| } | ||
| } | ||
| await systemUnderTest.await { /* Drain the queue */ } | ||
| await systemUnderTest.await(on: counter) { _ in /* Drain the queue */ } |
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'm tempted to add a new internal method called func allEnqueuedTasksSuspendedOrCompleted() async to make this test call-site read more clearly since we have a few of these.
15d770f to
37c441d
Compare
37c441d to
261001f
Compare
Codecov Report
@@ Coverage Diff @@
## dfed--fifo-vs-actor #7 +/- ##
=====================================================
Coverage 100.00% 100.00%
=====================================================
Files 2 2
Lines 95 95
=====================================================
Hits 95 95
|
|
Removing reviewers and bringing this PR back to drafts. Had some ideas I want to play with – I may be able to simplify call-sites make the async for-loop run on the target actor's context. |
|
Ideally the ActorQueue would run entirely on its target actor's execution context, but that's not possible today given how I'm going to close this out for now, though I'll want to explore this path more in the future. |
This PR is built on #3
This PR is similar to #6 but applied to the
ActorQueue. However, rather than adding API, this PR replaces existingasyncandawaitAPI with methods where thetasks sent to the queue to execute on the designatedactor's context.The goals of this PR are:
taskwithout requiring multiple suspension points (awaitcalls) within the `taskawaitcalls within a singletaskactually result in suspensionThese goals are important because an
ActorQueue'staskallows other tasks to begin execution as soon as thetasksuspends (via anawait). SinceActorQueues should only be utilized with a singleactorinstance, it made sense to replace the existing API rather than add new API – there's no good reason (that I can come up with) to use the the replaced APIs now that these new APIs exist.All that said, I don't love this API change.
ActorQueues are meant to be used as private implementation details of anactor, and as such theisolatedActorthat will be sent to theActorQueue's API is almost always going to beself. The big drawback of this change is that Swift doesn't allow parameters to a closure to be namedself, soActorQueuecalls will likely end up looking like the following:If someone were to try to ignore the parameter in the closure, they'd end up having to write an
await:I really like the goals I'm trying to achieve, but I don't love how the semantics play out. Curious to get your thoughts!