Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sendable annotations to new async APIs #427

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,22 @@ extension NIOHTTP2Handler {
/// You can open a stream by calling ``openStream(_:)``. Locally-initiated stream channel objects are initialized upon creation using the supplied `initializer` which returns a type
/// `Output`. This type may be `HTTP2Frame` or changed to any other type.
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public struct AsyncStreamMultiplexer<InboundStreamOutput> {
private let inlineStreamMultiplexer: InlineStreamMultiplexer
public struct AsyncStreamMultiplexer<InboundStreamOutput: Sendable>: Sendable {
private let inlineStreamMultiplexer: NIOLoopBound<InlineStreamMultiplexer>
private let eventLoop: any EventLoop
public let inbound: NIOHTTP2AsyncSequence<InboundStreamOutput>

// Cannot be created by users.
internal init(_ inlineStreamMultiplexer: InlineStreamMultiplexer, continuation: any AnyContinuation, inboundStreamChannels: NIOHTTP2AsyncSequence<InboundStreamOutput>) {
self.inlineStreamMultiplexer = inlineStreamMultiplexer
self.inlineStreamMultiplexer.setChannelContinuation(continuation)
internal init(
_ inlineStreamMultiplexer: InlineStreamMultiplexer,
continuation: any AnyContinuation,
inboundStreamChannels: NIOHTTP2AsyncSequence<InboundStreamOutput>,
eventLoop: any EventLoop
) {
self.inlineStreamMultiplexer = NIOLoopBound(inlineStreamMultiplexer, eventLoop: eventLoop)
inlineStreamMultiplexer.setChannelContinuation(continuation)
self.inbound = inboundStreamChannels
self.eventLoop = eventLoop
}


Expand All @@ -246,7 +253,9 @@ extension NIOHTTP2Handler {
/// initializing the stream's `Channel`.
/// - Returns: The result of the `initializer`.
public func openStream<Output: Sendable>(_ initializer: @escaping NIOChannelInitializerWithOutput<Output>) async throws -> Output {
return try await self.inlineStreamMultiplexer.createStreamChannel(initializer).get()
return try await self.eventLoop.submit {
self.inlineStreamMultiplexer.value.createStreamChannel(initializer)
}.flatMap { $0 }.get()
}
}
}
7 changes: 6 additions & 1 deletion Sources/NIOHTTP2/HTTP2ChannelHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,12 @@ extension NIOHTTP2Handler {

switch self.inboundStreamMultiplexer {
case let .some(.inline(multiplexer)):
return AsyncStreamMultiplexer(multiplexer, continuation: continuation, inboundStreamChannels: inboundStreamChannels)
return AsyncStreamMultiplexer(
multiplexer,
continuation: continuation,
inboundStreamChannels: inboundStreamChannels,
eventLoop: self.eventLoop!
)
case .some(.legacy), .none:
throw NIOHTTP2Errors.missingMultiplexer()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOHTTP2/HTTP2PipelineHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ extension ChannelPipeline.SynchronousOperations {
}

/// `NIONegotiatedHTTPVersion` is a generic negotiation result holder for HTTP/1.1 and HTTP/2
public enum NIONegotiatedHTTPVersion<HTTP1Output: Sendable, HTTP2Output: Sendable> {
public enum NIONegotiatedHTTPVersion<HTTP1Output: Sendable, HTTP2Output: Sendable>: Sendable {
/// Protocol negotiation resulted in the connection using HTTP/1.1.
case http1_1(HTTP1Output)
/// Protocol negotiation resulted in the connection using HTTP/2.
Expand Down