Repository: apple/swift-nio
File: Sources/NIOCore/EventLoopFuture.swift (Swift)

Code before:
            callback(self._value!)
            return CallbackList()
        }
    }

    /// Internal: Set the value and return a list of callbacks that should be invoked as a result.
    @inlinable
    internal func _setValue(value: Result<Value, Error>) -> CallbackList {
        self.eventLoop.assertInEventLoop()
        if self._value == nil {
            self._value = value
            let callbacks = self._callbacks
            self._callbacks = CallbackList()
            return callbacks
        }
        return CallbackList()
    }

    #if swift(>=5.7)
    /// Adds an observer callback to this `EventLoopFuture` that is called when the
    /// `EventLoopFuture` has a success result, asserting a failure if it encounters an error.
    ///
    /// - parameters:
    ///     - callback: The callback that is called with the successful result of the `EventLoopFuture`.
    @inlinable
    @preconcurrency
    public func assertSuccess(_ callback: @escaping @Sendable (Value) -> Void) {
        self._assertSuccess(callback)
    }
    @usableFromInline typealias AssertSuccessCallback = @Sendable (Value) -> Void
    #else
    /// Adds an observer callback to this `EventLoopFuture` that is called when the
    /// `EventLoopFuture` has a success result, asserting a failure if it encounters an error.
    ///
    /// - parameters:
    ///     - callback: The callback that is called with the successful result of the `EventLoopFuture`.
    @inlinable
    public func assertSuccess(_ callback: @escaping (Value) -> Void) {
        self._assertSuccess(callback)
    }
    @usableFromInline typealias AssertSuccessCallback = (Value) -> Void
    #endif

    @inlinable
    func _assertSuccess(_ callback: @escaping AssertSuccessCallback) {
        self.whenComplete { result in
            switch result {
            case .success(let value):
                callback(value)
            case .failure(let error):
                assertionFailure("Expected success, but got failure: \(error)")

Review comment (suggestion):
As these are new methods they don't need `@preconcurrency` and also no special treatment in Swift 5.6. We can therefore just have a single declaration and implementation. 

I'm with @Lukasa though and we should make these methods return an `EventLoopFuture` instead. Therefore we will drop the `@Sendable` function argument all together and AFAICT don't have to deal with `Sendable` at all.

Code after:
            callback(self._value!)
            return CallbackList()
        }
    }

    /// Internal: Set the value and return a list of callbacks that should be invoked as a result.
    @inlinable
    internal func _setValue(value: Result<Value, Error>) -> CallbackList {
        self.eventLoop.assertInEventLoop()
        if self._value == nil {
            self._value = value
            let callbacks = self._callbacks
            self._callbacks = CallbackList()
            return callbacks
        }
        return CallbackList()
    }
}

// MARK: and

extension EventLoopFuture {
    /// Return a new `EventLoopFuture` that succeeds when this "and" another
    /// provided `EventLoopFuture` both succeed. It then provides the pair
    /// of results. If either one fails, the combined `EventLoopFuture` will fail with
    /// the first error encountered.
    @inlinable
    public func and<OtherValue>(_ other: EventLoopFuture<OtherValue>) -> EventLoopFuture<(Value, OtherValue)> {
        let promise = EventLoopPromise<(Value, OtherValue)>.makeUnleakablePromise(eventLoop: self.eventLoop)
        let box: UnsafeMutableTransferBox<(t:Value?, u: OtherValue?)> = .init((nil, nil))

        assert(self.eventLoop === promise.futureResult.eventLoop)
        self._whenComplete { () -> CallbackList in
            switch self._value! {
            case .failure(let error):
                return promise._setValue(value: .failure(error))
            case .success(let t):
                if let u = box.wrappedValue.u {
                    return promise._setValue(value: .success((t, u)))
                } else {
                    box.wrappedValue.t = t
                }
            }
            return CallbackList()
        }

        let hopOver = other.hop(to: self.eventLoop)
        hopOver._whenComplete { () -> CallbackList in
            self.eventLoop.assertInEventLoop()
            switch other._value! {
            case .failure(let error):