apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
7.94k stars 645 forks source link

Give NIOLoopBoundBox a `sending` off-EL initialiser once compiler is ready #2754

Open weissi opened 3 months ago

weissi commented 3 months ago

https://github.com/swiftlang/swift-evolution/blob/main/proposals/0430-transferring-parameters-and-results.md will be useful to construct NIOLoopBoundBox with a non-Sendable value off EL.

But the compiler isn't ready quite yet.

This is a followup for #2753 (which allows Sendable values)


#if compiler(>=6.0) // `sending` is >= 6.0
extension NIOLoopBoundBox {
    /// Initialise a ``NIOLoopBoundBox`` by `sending` (i.e. transferring) a value, validly callable off `eventLoop`.
    ///
    /// Contrary to ``init(_:eventLoop:)``, this method can be called off `eventLoop` because we are `sending` the value across the isolation domain.
    /// Because we're `sending` `value`, we just need to protect it against mutations (because nothing else can have access to it anymore).
    public static func makeBoxSendingValue(
        _ value: sending Value,
        as: Value.Type = Value.self,
        eventLoop: EventLoop
    ) -> NIOLoopBoundBox<Value> {
        ...
    }
}
#endif