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

Fix SchedulerTypeTime distance(to:) #104

Merged
merged 2 commits into from
Feb 3, 2021

Conversation

mayoff
Copy link

@mayoff mayoff commented Feb 2, 2021

The new versions of RunLoop and OperationQueue (copied from the Apple implementations) have incorrect implementations of SchedulerTimeType::distance(to:).

The original Apple implementations rely on Date::distance(to:), which is only available on the 2019 and later systems. So CombineX replaces the use of Date::distance(to:) with Date::timeIntervalSince(_:).

The problem is that the calls to timeIntervalSince have date and other.date in the wrong places, so each call to distance(to:) returns a Stride with a flipped sign.

This pull request contains two commits.

The first commit adds a test case demonstrating the incorrect behavior. The test case succeeds when compiled with Combine and fails when compiled with CombineX. The test case is a little tricky because I was unable to make it compile with Combine using the RunLoop.CX.SchedulerTimeType type. I worked around it with type inference, so that it uses RunLoop.SchedulerTimeType when compiled with Combine and RunLoop.CX.SchedulerTimeType when compiled with CombineX.

The second commit fixes the two implementations of distance(to:).

@mayoff mayoff force-pushed the fix-SchedulerTimeType-distance branch from f8914eb to 7781e8b Compare February 3, 2021 00:00
Rob Mayoff added 2 commits February 2, 2021 18:01
These tests fail because CombineX's RunLoop.CX.SchedulerTimeType and
OperationQueue.CX.SchedulerTimeType have incorrect implementations of
the distance(to:) method.
@mayoff mayoff force-pushed the fix-SchedulerTimeType-distance branch from 7781e8b to f97d175 Compare February 3, 2021 00:01
@mayoff
Copy link
Author

mayoff commented Feb 3, 2021

I noticed how the other tests (in the same file, duh) were using CXWrappers and used it to abstract away the type names in the new test.

@ddddxxx
Copy link
Member

ddddxxx commented Feb 3, 2021

Looks great! I just fixed falling tests irrelevant to this pr. Would you mind rebase and run checks again?

Edit: There is no need to do so. I'll just merge it. Thank you!

@ddddxxx ddddxxx merged commit 973cc9b into cx-org:master Feb 3, 2021
@ddddxxx
Copy link
Member

ddddxxx commented Feb 10, 2021

@mayoff Hi, I noticed the CXShim solution is rather complicated for people new to CombineX. So I wrote a migration guide. Feedbacks are welcomed!

garvankeeley added a commit to garvankeeley/CombineX that referenced this pull request Mar 11, 2021
garvankeeley added a commit to garvankeeley/CombineX that referenced this pull request Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants