Initial PoC of Custom Actor Executor support (#2388)

* Support NIO Event Loops as actor executors

Motivation

Swift Concurrency supports having actors opt in to executing
within a "custom executor". This requires being able to be strictly
serial, a constraint that NIO's EventLoops natively meet. It is
useful to have actors be able to express a "tie" to an EventLoop
in order to efficiently access objects that are tied to specific ELs.

Modifications

- Extend EventLoop to expose an executor property
- Provide a simple best-effort default using NIODefaultSerialEventLoopExecutor
- Expose NIOSerialEventLoopExecutor protocol that makes it easy
  for adopters to get a better implementation
- Crash if EmbeddedEventLoop is used
- Add tests

Result

Adopters can use ELs as serial executors

* Prefer #if compiler
This commit is contained in:
Cory Benfield authored and GitHub committed 2023-07-31 07:19:49 -07:00
1 parent e20271f4a3
commit 5be5ccb5a7
6 files changed
+196

No files matched your search

@@ -349,6 +349,12 @@ public final class NIOAsyncTestingEventLoop: EventLoop, @unchecked Sendable {
}
}
// MARK: SerialExecutor conformance
#if compiler(>=5.9)
@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
extension NIOAsyncTestingEventLoop: NIOSerialEventLoopExecutor { }
#endif
/// This is a thread-safe promise creation store.
///
/// We use this to keep track of where promises come from in the `NIOAsyncTestingEventLoop`.