mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
Motivation: `EmbeddedEventLoop` executes scheduled tasks in their run-time order. If multiple tasks are scheduled for the same time then the order in which they are eventually executed is undefined. Since `execute` defers to scheduling a task for "now" it is possible for tasks to be executed out of order if `run()` is not called between each execute. In "real" event loops this isn't an issue because the system time must advance between each call to `execute`. Modifications: - Add a 'insertionOrder' to `EmbeddedScheduledTask`; use it to break ties when comparing two tasks with the same run time - Add a task counter to `EmbeddedEventLoop` which is used to provide an insertion order when scheduling tasks. Result: - EmbeddedEventLoop will `execute` tasks in order