diff --git a/Sources/NIOTransportServices/NIOTSEventLoop.swift b/Sources/NIOTransportServices/NIOTSEventLoop.swift index da8980d..9ff9631 100644 --- a/Sources/NIOTransportServices/NIOTSEventLoop.swift +++ b/Sources/NIOTransportServices/NIOTSEventLoop.swift @@ -121,16 +121,15 @@ internal class NIOTSEventLoop: QoSEventLoop { public func scheduleTask(deadline: NIODeadline, qos: DispatchQoS, _ task: @escaping () throws -> T) -> Scheduled { let p: EventLoopPromise = self.makePromise() - guard self.state != .closed else { - p.fail(EventLoopError.shutdown) - return Scheduled(promise: p, cancellationTask: { } ) - } - // Dispatch support for cancellation exists at the work-item level, so we explicitly create one here. // We set the QoS on this work item and explicitly enforce it when the block runs. let timerSource = DispatchSource.makeTimerSource(queue: self.taskQueue) timerSource.schedule(deadline: DispatchTime(uptimeNanoseconds: deadline.uptimeNanoseconds)) timerSource.setEventHandler(qos: qos, flags: .enforceQoS) { + guard self.state != .closed else { + p.fail(EventLoopError.shutdown) + return + } do { p.succeed(try task()) } catch {