Adopt `Sendable` (#155)

* Adopt `Sendable`

* Workaround Swift 5.4 compiler bug
This commit is contained in:
David Nadoba 2022-08-31 17:22:32 +02:00 committed by GitHub
parent 4e02d9cf35
commit c2e373fec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 4 deletions

View File

@ -21,7 +21,7 @@ let package = Package(
.library(name: "NIOTransportServices", targets: ["NIOTransportServices"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.41.1"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],

View File

@ -85,6 +85,11 @@ public final class NIOFilterEmptyWritesHandler: ChannelDuplexHandler {
}
}
#if swift(>=5.6)
@available(*, unavailable)
extension NIOFilterEmptyWritesHandler: Sendable {}
#endif
// Connection state management
extension NIOFilterEmptyWritesHandler {
public func channelActive(context: ChannelHandlerContext) {

View File

@ -13,7 +13,11 @@
//===----------------------------------------------------------------------===//
#if canImport(Network)
import NIOCore
#if swift(>=5.6)
@preconcurrency import Network
#else
import Network
#endif
/// Options that can be set explicitly and only on bootstraps provided by `NIOTransportServices`.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)

View File

@ -238,6 +238,11 @@ public final class NIOTSConnectionBootstrap {
}
}
#if swift(>=5.6)
@available(*, unavailable)
extension NIOTSConnectionBootstrap: Sendable {}
#endif
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSConnectionBootstrap: NIOClientTCPBootstrapProtocol {
/// Apply any understood shorthand options to the bootstrap, removing them from the set of options if they are consumed.

View File

@ -120,3 +120,8 @@ public struct NIOTSClientTLSProvider: NIOClientTLSProvider {
}
}
#endif
#if swift(>=5.5) && canImport(_Concurrency) && canImport(Network)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSEventLoopGroup: @unchecked Sendable {}
#endif

View File

@ -346,7 +346,6 @@ public final class NIOTSListenerBootstrap {
}
}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
private class AcceptHandler: ChannelInboundHandler {
typealias InboundIn = NIOTSConnectionChannel

View File

@ -130,7 +130,6 @@ internal final class NIOTSListenerChannel {
}
}
// MARK:- NIOTSListenerChannel implementation of Channel
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSListenerChannel: Channel {
@ -495,3 +494,8 @@ extension NIOTSListenerChannel {
}
}
#endif
#if swift(>=5.5) && canImport(_Concurrency) && canImport(Network)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSListenerChannel: @unchecked Sendable {}
#endif

View File

@ -13,14 +13,18 @@
//===----------------------------------------------------------------------===//
#if canImport(Network)
#if swift(>=5.6)
@preconcurrency import Network
#else
import Network
#endif
import NIOCore
/// A tag protocol that can be used to cover all network events emitted by `NIOTransportServices`.
///
/// Users are strongly encouraged not to conform their own types to this protocol.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public protocol NIOTSNetworkEvent: Equatable { }
public protocol NIOTSNetworkEvent: Equatable, NIOPreconcurrencySendable { }
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public enum NIOTSNetworkEvents {
@ -98,4 +102,20 @@ public enum NIOTSNetworkEvents {
}
}
}
#if swift(>=5.6)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSNetworkEvents.BetterPathAvailable: Sendable {}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSNetworkEvents.BetterPathUnavailable: Sendable {}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSNetworkEvents.PathChanged: Sendable {}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSNetworkEvents.ConnectToNWEndpoint: Sendable {}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSNetworkEvents.BindToNWEndpoint: Sendable {}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSNetworkEvents.WaitingForConnectivity: Sendable {}
#endif
#endif