Repository: apple/swift-nio
File: Sources/NIOCore/EventLoop+SerialExecutor.swift (Swift)

Code before:
        // By default we are just going to use execute to run the job
        // this is quite heavy since it allocates the closure for
        // every single job.
        let unownedJob = UnownedJob(job)
        self.execute {
            unownedJob.runSynchronously(on: self.asUnownedSerialExecutor())
        }
    }

    @inlinable
    public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
        UnownedSerialExecutor(ordinary: self)
    }

    @inlinable
    public var executor: any SerialExecutor {
        self
    }

    @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
    @inlinable
    public func isSameExclusiveExecutionContext(other: Self) -> Bool {
        other === self
    }

    @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
    @inlinable
    public func checkIsolated() {
        self.preconditionInEventLoop()
    }
}

/// A type that wraps a NIO ``EventLoop`` into a `SerialExecutor`
/// for use with Swift concurrency.
///
/// This type is not recommended for use because it risks problems with unowned
/// executors. Adopters are recommended to conform their own event loop
/// types to `SerialExecutor`.
final class NIODefaultSerialEventLoopExecutor {
    @usableFromInline
    let loop: EventLoop

    @inlinable
    init(_ loop: EventLoop) {
        self.loop = loop
    }
}

@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
extension NIODefaultSerialEventLoopExecutor: SerialExecutor {
    @inlinable

Review comment (bug):
Should fix the compilation failures
```suggestion
    @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, *)
```

Code after:
        // By default we are just going to use execute to run the job
        // this is quite heavy since it allocates the closure for
        // every single job.
        let unownedJob = UnownedJob(job)
        self.execute {
            unownedJob.runSynchronously(on: self.asUnownedSerialExecutor())
        }
    }

    @inlinable
    public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
        UnownedSerialExecutor(complexEquality: self)
    }

    @inlinable
    public var executor: any SerialExecutor {
        self
    }

    @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
    @inlinable
    public func isSameExclusiveExecutionContext(other: Self) -> Bool {
        other === self
    }

    @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, *)
    @inlinable
    public func checkIsolated() {
        self.preconditionInEventLoop()
    }
}

/// A type that wraps a NIO ``EventLoop`` into a `SerialExecutor`
/// for use with Swift concurrency.
///
/// This type is not recommended for use because it risks problems with unowned
/// executors. Adopters are recommended to conform their own event loop
/// types to `SerialExecutor`.
final class NIODefaultSerialEventLoopExecutor {
    @usableFromInline
    let loop: EventLoop

    @inlinable
    init(_ loop: EventLoop) {
        self.loop = loop
    }
}

@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
extension NIODefaultSerialEventLoopExecutor: SerialExecutor {
    @inlinable