-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Implement AsyncEventLoopExecutor to lay foundation #11
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
base: build/setUpInitialPackageAndCI
Are you sure you want to change the base?
feat: Implement AsyncEventLoopExecutor to lay foundation #11
Conversation
…ng AsyncEventLoop.
2b0a755 to
2eca931
Compare
| failFn: @Sendable @escaping (Error) -> Void | ||
| ) -> UUID { | ||
| let id = UUID() | ||
| Task { @_AsyncEventLoopExecutor._IsolatingSerialEntryActor [delay, job, weak self] in |
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.
Can you pick something besides the @mainactor now?
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.
@CrownedPhoenix Yep. That is what I'm doing here. @_AsyncEventLoopExecutor._IsolatingSerialEntryActor is equivalent to @MainActor, except that it forms it's own task pool separate from but similar to @MainActor.
| await run() | ||
| await awaitPendingEntryOperations() | ||
| if let existingTask = currentlyRunningExecutorTask { | ||
| _ = await existingTask.value | ||
| } |
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.
Is reentrancy a problem here?
| @available(macOS 13, *) | ||
| enum _CurrentEventLoopKey { @TaskLocal static var id: UUID? } | ||
|
|
||
| /// This is an actor designed to execute provided tasks in the order then enter the actor. |
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 is an actor designed to execute provided tasks in the order then enter the actor. | |
| /// This is an actor designed to execute provided tasks in the order they enter the actor. |
| ) -> UUID { | ||
| let id = UUID() | ||
| Task { @_AsyncEventLoopExecutor._IsolatingSerialEntryActor [delay, job, weak self] in | ||
| // ^----- Ensures FIFO entry from nonisolated contexts |
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.
| // ^----- Ensures FIFO entry from nonisolated contexts | |
| // ^----- Ensures first-in entry from nonisolated contexts |
| } | ||
| } | ||
|
|
||
| /// We use this actor to make serialized FIFO entry |
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 use this actor to make serialized FIFO entry | |
| /// We use this actor to make serialized first-in entry |
|
|
||
| nonisolated func enqueue(_ job: @Sendable @escaping () -> Void) { | ||
| Task { @_AsyncEventLoopExecutor._IsolatingSerialEntryActor [job, weak self] in | ||
| // ^----- Ensures FIFO entry from nonisolated contexts |
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.
| // ^----- Ensures FIFO entry from nonisolated contexts | |
| // ^----- Ensures first-in entry from nonisolated contexts |
|
|
||
| nonisolated func cancelScheduledJob(withID id: UUID) { | ||
| Task { @_AsyncEventLoopExecutor._IsolatingSerialEntryActor [id, weak self] in | ||
| // ^----- Ensures FIFO entry from nonisolated contexts |
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.
| // ^----- Ensures FIFO entry from nonisolated contexts | |
| // ^----- Ensures first-in entry from nonisolated contexts |
| ) -> UUID { | ||
| let id = UUID() | ||
| Task { @_AsyncEventLoopExecutor._IsolatingSerialEntryActor [job, weak self] in | ||
| // ^----- Ensures FIFO entry from nonisolated contexts |
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.
| // ^----- Ensures FIFO entry from nonisolated contexts | |
| // ^----- Ensures first-in entry from nonisolated contexts |
|
Did this start as copy-pasta from a NIO implementation and then get pruned down to rip out unavailable dependencies? |
| /// enqueing themselves. | ||
| private func awaitPendingEntryOperations() async { | ||
| await Task { @_IsolatingSerialEntryActor [] in | ||
| // ^----- Ensures FIFO entry from nonisolated contexts |
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.
| // ^----- Ensures FIFO entry from nonisolated contexts | |
| // ^----- Ensures first-in entry from nonisolated contexts |
Summary
Implement AsyncEventLoopExecutor that forms the basis of operations for NIOAsyncRuntime
Details
Usage Examples
Testing Performed
Tests coverage provided in tests ported from NIOPosix: #6.
The changes have also been tested in real-world application by running
GraphManagerandQuantumProjectManagerin the browser to migrate database schemas, connect with our server, and pull data from a real user account.PR Dependencies
#3
Overview of all changes
All planned changes can be viewed together in #2