Skip to content

Commit

Permalink
Track execute() and enqueue() tasks separately from scheduled tas…
Browse files Browse the repository at this point in the history
…ks. (#2645)
  • Loading branch information
gmilos committed Mar 5, 2024
1 parent 53be205 commit 5e47077
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 110 deletions.
27 changes: 4 additions & 23 deletions Sources/NIOPosix/MultiThreadedEventLoopGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,47 +421,28 @@ struct ErasedUnownedJob {

@usableFromInline
internal struct ScheduledTask {
@usableFromInline
enum UnderlyingTask {
case function(() -> Void)
#if compiler(>=5.9)
case unownedJob(ErasedUnownedJob)
#endif
}

/// The id of the scheduled task.
///
/// - Important: This id has two purposes. First, it is used to give this struct an identity so that we can implement ``Equatable``
/// Second, it is used to give the tasks an order which we use to execute them.
/// This means, the ids need to be unique for a given ``SelectableEventLoop`` and they need to be in ascending order.
@usableFromInline
let id: UInt64
let task: UnderlyingTask
private let failFn: ((Error) ->())?
let task: () -> Void
private let failFn: (Error) -> Void
@usableFromInline
internal let readyTime: NIODeadline

@usableFromInline
init(id: UInt64, _ task: @escaping () -> Void, _ failFn: @escaping (Error) -> Void, _ time: NIODeadline) {
self.id = id
self.task = .function(task)
self.task = task
self.failFn = failFn
self.readyTime = time
}

#if compiler(>=5.9)
@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
@usableFromInline
init(id: UInt64, job: consuming ExecutorJob, readyTime: NIODeadline) {
self.id = id
self.task = .unownedJob(.init(job: UnownedJob(job)))
self.readyTime = readyTime
self.failFn = nil
}
#endif

func fail(_ error: Error) {
failFn?(error)
failFn(error)
}
}

Expand Down

0 comments on commit 5e47077

Please sign in to comment.