Repository: apple/swift-nio
File: Sources/NIOPosix/SelectableEventLoop.swift (Swift)

Code before:

    /// - see: `EventLoop.now`
    @usableFromInline
    internal var now: NIODeadline {
        .now()
    }

    /// - see: `EventLoop.scheduleTask(deadline:_:)`
    @inlinable
    internal func scheduleTask<T>(deadline: NIODeadline, _ task: @escaping () throws -> T) -> Scheduled<T> {
        let promise: EventLoopPromise<T> = self.makePromise()
        let (task, scheduled) = self._prepareToSchedule(deadline: deadline, promise: promise, task: task)

        do {
            try self._schedule0(.scheduled(task))
        } catch {
            promise.fail(error)
        }

        return scheduled
    }

    /// - see: `EventLoop.scheduleTask(in:_:)`
    @inlinable
    internal func scheduleTask<T>(in: TimeAmount, _ task: @escaping () throws -> T) -> Scheduled<T> {
        scheduleTask(deadline: .now() + `in`, task)
    }

    @inlinable
    func _prepareToSchedule<T>(
        deadline: NIODeadline,
        promise: EventLoopPromise<T>,
        task: @escaping () throws -> T
    ) -> (ScheduledTask, Scheduled<T>) {
        let task = ScheduledTask(
            id: self.scheduledTaskCounter.loadThenWrappingIncrement(ordering: .relaxed),
            {
                do {
                    promise.succeed(try task())
                } catch let err {
                    promise.fail(err)
                }
            },
            { error in
                promise.fail(error)
            },
            deadline
        )

        let taskId = task.id
        let scheduled = Scheduled(

Review comment (suggestion):
```suggestion
        self.scheduleTask(deadline: .now() + `in`, task)
```

Code after:

    /// - see: `EventLoop.now`
    @usableFromInline
    internal var now: NIODeadline {
        .now()
    }

    /// - see: `EventLoop.scheduleTask(deadline:_:)`
    @inlinable
    internal func scheduleTask<T>(deadline: NIODeadline, _ task: @escaping () throws -> T) -> Scheduled<T> {
        let promise: EventLoopPromise<T> = self.makePromise()
        let (task, scheduled) = self._prepareToSchedule(deadline: deadline, promise: promise, task: task)

        do {
            try self._schedule0(.scheduled(task))
        } catch {
            promise.fail(error)
        }

        return scheduled
    }

    /// - see: `EventLoop.scheduleTask(in:_:)`
    @inlinable
    internal func scheduleTask<T>(in: TimeAmount, _ task: @escaping () throws -> T) -> Scheduled<T> {
        self.scheduleTask(deadline: .now() + `in`, task)
    }

    @inlinable
    func _prepareToSchedule<T>(
        deadline: NIODeadline,
        promise: EventLoopPromise<T>,
        task: @escaping () throws -> T
    ) -> (ScheduledTask, Scheduled<T>) {
        let task = ScheduledTask(
            id: self.scheduledTaskCounter.loadThenWrappingIncrement(ordering: .relaxed),
            {
                do {
                    promise.succeed(try task())
                } catch let err {
                    promise.fail(err)
                }
            },
            { error in
                promise.fail(error)
            },
            deadline
        )

        let taskId = task.id
        let scheduled = Scheduled(