Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EventLoop.now API for getting the current time #3015

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

simonjbeaumont
Copy link
Contributor

@simonjbeaumont simonjbeaumont commented Dec 3, 2024

Motivation

Code that tries to work with NIODeadline can be challenging to test using EmbeddedEventLoop and NIOAsyncTestingEventLoop because they have their own, fake clock.

These testing event loops do implement scheduleTask(in:_) to submit work in the future, relative to the event loop clock, but there is no way to get the event loop's current notion of "now", as a NIODeadline, and users sometimes find that NIODeadline.now, which returns the time of the real clock, to be surprising.

Modifications

Add EventLoop.now to get the current time of the event loop clock.

Result

New APIs to support writing code that's easier to test.

Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One typo, but looks good otherwise!

Sources/NIOCore/EventLoop.swift Outdated Show resolved Hide resolved
@simonjbeaumont simonjbeaumont marked this pull request as ready for review December 6, 2024 16:25
@simonjbeaumont simonjbeaumont enabled auto-merge (squash) December 6, 2024 16:25
@simonjbeaumont simonjbeaumont merged commit c3a8d18 into apple:main Dec 6, 2024
32 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants