mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-22 04:30:42 +00:00
Motivation: `RequestResponseHandler` and `RequestResponseWithIDHandler` previously allowed non-`Sendable` Requests to move across event loops by wrapping it in `UnsafeTransfer`, which disabled the compiler's sendability checking. Requiring every Response to be `Sendable` would solve the safety issue but it limits how the handlers can be used. Modifications: * Extracted the common logic of both handlers into a single state machine. * Modified the original implementations to have Request conform to `Sendable` * Introduced two new variants that don't care if the Request is `Sendable` as promises moving to different event loops would be failed with an error. * Removed the UnsafeTransfer type as it is not used anymore. * Added unit tests to confirm that the Sendable variants allow for promises for different event loops and non-Sendable variants fail the promises with an Error. Result: * Compiler's sendability checks are restored for the handlers. --------- Co-authored-by: George Barnett <gbarnett@apple.com>
33 lines
1.1 KiB
Swift
33 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2017-2025 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
import NIOCore
|
|
|
|
/// Base type for errors from NIOExtras
|
|
public protocol NIOExtrasError: Equatable, Error {}
|
|
|
|
/// Errors that are raised in NIOExtras.
|
|
public enum NIOExtrasErrors: Sendable {
|
|
|
|
/// Error indicating that after an operation some unused bytes are left.
|
|
public struct LeftOverBytesError: NIOExtrasError {
|
|
public let leftOverBytes: ByteBuffer
|
|
}
|
|
|
|
/// The channel was closed before receiving a response to a request.
|
|
public struct ClosedBeforeReceivingResponse: NIOExtrasError {}
|
|
|
|
/// Error indicating the response promise buffer is empty.
|
|
public struct ResponsePromiseBufferEmpty: NIOExtrasError {}
|
|
}
|