|
| 1 | +// RUN: %target-swift-frontend -enable-experimental-move-only %s -emit-sil -o /dev/null -verify |
| 2 | +// RUN: %target-swift-frontend -enable-experimental-move-only %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted |
| 3 | +// RUN: %target-swift-frontend -enable-experimental-move-only %s -emit-sil -o /dev/null -verify -strict-concurrency=complete |
| 4 | +// RUN: %target-swift-frontend -enable-experimental-move-only %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -enable-experimental-feature SendNonSendable |
| 5 | + |
| 6 | +// REQUIRES: concurrency |
| 7 | + |
| 8 | +public protocol EventLoop: Sendable {} |
| 9 | + |
| 10 | +#if compiler(>=5.9) |
| 11 | +/// A helper protocol that can be mixed in to a NIO ``EventLoop`` to provide an |
| 12 | +/// automatic conformance to `SerialExecutor`. |
| 13 | +/// |
| 14 | +/// Implementers of `EventLoop` should consider conforming to this protocol as |
| 15 | +/// well on Swift 5.9 and later. |
| 16 | +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) |
| 17 | +public protocol NIOSerialEventLoopExecutor: EventLoop, SerialExecutor { } |
| 18 | + |
| 19 | +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) |
| 20 | +extension NIOSerialEventLoopExecutor { |
| 21 | + @inlinable |
| 22 | + public func enqueue(_ job: consuming ExecutorJob) { |
| 23 | + fatalError("mock impl") |
| 24 | + } |
| 25 | + |
| 26 | + @inlinable |
| 27 | + public func asUnownedSerialExecutor() -> UnownedSerialExecutor { |
| 28 | + UnownedSerialExecutor(ordinary: self) |
| 29 | + } |
| 30 | + |
| 31 | + @inlinable |
| 32 | + public var executor: any SerialExecutor { |
| 33 | + self |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// EARLIER AVAILABILITY |
| 38 | +final class NIODefaultSerialEventLoopExecutor { |
| 39 | + @usableFromInline |
| 40 | + let loop: EventLoop |
| 41 | + |
| 42 | + @inlinable |
| 43 | + init(_ loop: EventLoop) { |
| 44 | + self.loop = loop |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) |
| 49 | +extension NIODefaultSerialEventLoopExecutor: SerialExecutor { |
| 50 | + @inlinable |
| 51 | + public func enqueue(_ job: consuming ExecutorJob) { // do NOT issue a warning here |
| 52 | + fatalError("mock impl") |
| 53 | + } |
| 54 | + |
| 55 | + @inlinable |
| 56 | + public func asUnownedSerialExecutor() -> UnownedSerialExecutor { |
| 57 | + UnownedSerialExecutor(complexEquality: self) |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | + @inlinable |
| 62 | + public func isSameExclusiveExecutionContext(other: NIODefaultSerialEventLoopExecutor) -> Bool { |
| 63 | + false |
| 64 | + } |
| 65 | +} |
| 66 | +#endif |
0 commit comments