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

Code before:
    public func scheduleCallback(
        in amount: TimeAmount,
        handler: some NIOScheduledCallbackHandler
    ) throws -> NIOScheduledCallback {
        try self._wrapped._scheduleCallbackIsolatedUnsafeUnchecked(in: amount, handler: handler)
    }

    @inlinable
    @available(*, noasync)
    public func cancelScheduledCallback(_ scheduledCallback: NIOScheduledCallback) {
        self._wrapped.cancelScheduledCallback(scheduledCallback)
    }

    /// Creates and returns a new `EventLoopFuture` that is already marked as success. Notifications
    /// will be done using this `EventLoop` as execution `NIOThread`.
    ///
    /// - Parameters:
    ///   - value: the value that is used by the `EventLoopFuture`.
    /// - Returns: a succeeded `EventLoopFuture`.
    @inlinable
    @available(*, noasync)
    public func makeSucceededFuture<Success>(_ value: Success) -> EventLoopFuture<Success> {
        let promise = self._wrapped.makePromise(of: Success.self)
        promise.assumeIsolatedUnsafeUnchecked().succeed(value)
        return promise.futureResult
    }

    /// Creates and returns a new `EventLoopFuture` that is already marked as failed. Notifications
    /// will be done using this `EventLoop`.
    ///
    /// - Parameters:
    ///   - error: the `Error` that is used by the `EventLoopFuture`.
    /// - Returns: a failed `EventLoopFuture`.
    @inlinable
    @available(*, noasync)
    public func makeFailedFuture<Success>(_ error: Error) -> EventLoopFuture<Success> {
        let promise = self._wrapped.makePromise(of: Success.self)
        promise.fail(error)
        return promise.futureResult
    }

    /// Creates and returns a new `EventLoopFuture` that is marked as succeeded or failed with the
    /// value held by `result`.
    ///
    /// - Parameters:
    ///   - result: The value that is used by the `EventLoopFuture`
    /// - Returns: A completed `EventLoopFuture`.
    @inlinable
    @available(*, noasync)
    public func makeCompletedFuture<Success>(_ result: Result<Success, Error>) -> EventLoopFuture<Success> {
        let promise = self._wrapped.makePromise(of: Success.self)

Review comment (suggestion):
The checking strategy here is incoherent. Methods that are marked `unsafeUnchecked` should have asserts. Methods without that need `preconditions`.

Code after:
    ) throws -> NIOScheduledCallback {
        try self._wrapped._scheduleCallbackIsolatedUnsafeUnchecked(at: deadline, handler: handler)
    }

    /// Schedule a callback after given time.
    ///
    /// - Parameters:
    ///   - amount: The amount of time before which the task will not execute.
    ///   - handler: The handler that defines the behavior of the callback when executed or canceled.
    ///  - Returns: A ``NIOScheduledCallback`` that can be used to cancel the scheduled callback.
    @discardableResult
    @available(*, noasync)
    @inlinable
    public func scheduleCallback(
        in amount: TimeAmount,
        handler: some NIOScheduledCallbackHandler
    ) throws -> NIOScheduledCallback {
        try self._wrapped._scheduleCallbackIsolatedUnsafeUnchecked(in: amount, handler: handler)
    }

    /// Cancel a scheduled callback.
    @inlinable
    @available(*, noasync)
    public func cancelScheduledCallback(_ scheduledCallback: NIOScheduledCallback) {
        self._wrapped.preconditionInEventLoop()
        self._wrapped.cancelScheduledCallback(scheduledCallback)
    }

    /// Creates and returns a new `EventLoopFuture` that is already marked as success. Notifications
    /// will be done using this `EventLoop` as execution `NIOThread`.
    ///
    /// - Parameters:
    ///   - value: the value that is used by the `EventLoopFuture`.
    /// - Returns: a succeeded `EventLoopFuture`.
    @inlinable
    @available(*, noasync)
    public func makeSucceededFuture<Success>(_ value: Success) -> EventLoopFuture<Success> {
        let promise = self._wrapped.makePromise(of: Success.self)
        promise.assumeIsolatedUnsafeUnchecked().succeed(value)
        return promise.futureResult
    }

    /// Creates and returns a new `EventLoopFuture` that is already marked as failed. Notifications
    /// will be done using this `EventLoop`.
    ///
    /// - Parameters:
    ///   - error: the `Error` that is used by the `EventLoopFuture`.
    /// - Returns: a failed `EventLoopFuture`.
    @inlinable
    @available(*, noasync)
    public func makeFailedFuture<Success>(_ error: Error) -> EventLoopFuture<Success> {