Move check for event loop shutdown into taskQueue (#127)
Motivation: The event loop state is not protected for access on different threads. This means it must only be accessed from the task queue. Modifications: Move check for event loop shutdown into taskQueue Result: Event Loop state only accessed from the task queue.
This commit is contained in:
parent
5fd5ba4d3e
commit
9571a61d23
|
|
@ -121,16 +121,15 @@ internal class NIOTSEventLoop: QoSEventLoop {
|
|||
public func scheduleTask<T>(deadline: NIODeadline, qos: DispatchQoS, _ task: @escaping () throws -> T) -> Scheduled<T> {
|
||||
let p: EventLoopPromise<T> = 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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue