Repository: apple/swift-nio
File: Sources/NIOEmbedded/AsyncTestingChannel.swift (Swift)

Code before:
    public func getOption<Option: ChannelOption>(_ option: Option) -> EventLoopFuture<Option.Value> {
        if self.eventLoop.inEventLoop {
            return self.eventLoop.makeSucceededFuture(self.getOptionSync(option))
        } else {
            return self.eventLoop.submit { self.getOptionSync(option) }
        }
    }

    @inlinable
    internal func getOptionSync<Option: ChannelOption>(_ option: Option) -> Option.Value {
        if option is ChannelOptions.Types.AutoReadOption {
            return true as! Option.Value
        }
        if option is ChannelOptions.Types.AllowRemoteHalfClosureOption {
            return self.allowRemoteHalfClosure as! Option.Value
        }
        if option is ChannelOptions.Types.BufferedWritableBytesOption {
            let result = self.channelcore.pendingOutboundBuffer.reduce(0) { partialResult, dataAndPromise in
                let buffer = self.channelcore.unwrapData(dataAndPromise.0, as: ByteBuffer.self)
                return partialResult + buffer.readableBytes
            }

            return result as! Option.Value
        }

        guard let value = optionValue(for: option) else {
            fatalError("option \(option) not supported")
        }

        return value
    }

    @inlinable
    internal func optionValue<Option: ChannelOption>(for option: Option) -> Option.Value? {
        self.options.first(where: { $0.option is Option })?.value as? Option.Value
    }

    @inlinable
    internal func addOption<Option: ChannelOption>(_ option: Option, value: Option.Value) {
        // override the option if it exists
        _stateLock.withLockedValue { state in
            var options = state.options
            let optionIndex = options.firstIndex(where: { $0.option is Option })
            if let optionIndex = optionIndex {
               options[optionIndex] = (option, value)
            } else {
                options.append((option, value))
            }
            state.options = options
        }
    }

Review comment (suggestion):
Nit: 
```suggestion
        guard let value = self.optionValue(for: option) else {
```

Code after:
    public func getOption<Option: ChannelOption>(_ option: Option) -> EventLoopFuture<Option.Value> {
        if self.eventLoop.inEventLoop {
            return self.eventLoop.makeSucceededFuture(self.getOptionSync(option))
        } else {
            return self.eventLoop.submit { self.getOptionSync(option) }
        }
    }

    @inlinable
    internal func getOptionSync<Option: ChannelOption>(_ option: Option) -> Option.Value {
        if option is ChannelOptions.Types.AutoReadOption {
            return true as! Option.Value
        }
        if option is ChannelOptions.Types.AllowRemoteHalfClosureOption {
            return self.allowRemoteHalfClosure as! Option.Value
        }
        if option is ChannelOptions.Types.BufferedWritableBytesOption {
            let result = self.channelcore.pendingOutboundBuffer.reduce(0) { partialResult, dataAndPromise in
                let buffer = self.channelcore.unwrapData(dataAndPromise.0, as: ByteBuffer.self)
                return partialResult + buffer.readableBytes
            }

            return result as! Option.Value
        }

        guard let value = self.optionValue(for: option) else {
            fatalError("option \(option) not supported")
        }

        return value
    }

    @inlinable
    internal func optionValue<Option: ChannelOption>(for option: Option) -> Option.Value? {
        self.options.first(where: { $0.option is Option })?.value as? Option.Value
    }

    @inlinable
    internal func addOption<Option: ChannelOption>(_ option: Option, value: Option.Value) {
        // override the option if it exists
        self._stateLock.withLockedValue { state in
            var options = state.options
            let optionIndex = options.firstIndex(where: { $0.option is Option })
            if let optionIndex = optionIndex {
                options[optionIndex] = (option, value)
            } else {
                options.append((option, value))
            }
            state.options = options
        }
    }