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 async helpers to Schedulers #857

Merged

Conversation

p4checo
Copy link
Contributor

@p4checo p4checo commented Nov 8, 2022

Credits to @pointfreeco for the work done in:
https://github.com/pointfreeco/combine-schedulers

Changes

  • Add new async APIs to DateScheduler to enable waiting for them in asynchronous contexts:

    • sleep(for:leeway:) async
    • sleep(until:leeway:) async
    • timer(interval:leeway:) async
  • Add new async variants TestScheduler's advance and run APIs, to enable waiting for them in asynchronous contexts:

    • advance() async`
    • advance(by:) async (DispatchTimeInterval and TimeInterval)
    • advance(to:) async
    • run() async
  • Refactor TestScheduler.advance(to:)'s loop condition to be based on _currentDate instead of scheduledActions.count to be consistent with the new async variant.

Tests

  • I've not added any tests for now, as I would like to know if the solution/approach is accepted first.
  • Additionally, current Quick/Nimble setup apparently doesn't support async contexts yet as it's only available from Quick 6 (RAS is still on Quick 4). I can add them as vanilla async XCTests though.

Checklist

  • Updated CHANGELOG.md.

Copy link
Contributor

@mluisbrown mluisbrown left a comment

Choose a reason for hiding this comment

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

Nice job 👍

Credits to @pointfreeco for the work done in:
https://github.com/pointfreeco/combine-schedulers

## Changes

- Add new `async` APIs to `DateScheduler` to enable waiting for them in
asynchronous contexts:
  + `sleep(for:leeway) async`
  + `sleep(until:leeway) async`
  + `timer(interval:leeway) async`

- Add new `async` variants `TestScheduler`'s `advance` and `run` APIs,
to enable waiting for them in asynchronous contexts:
  + `advance()` async`
  + `advance(by:) async` (`DispatchTimeInterval` and `TimeInterval`)
  + `advance(to:) async`
  + `run() async`

- Refactor `TestScheduler.advance(to:)`'s loop condition to be based on
`_currentDate` instead of `scheduledActions.count` to be consistent
with the new `async` variant.

- Add `NSRecursiveLock.withLock` implementation for older OS versions.
@p4checo p4checo force-pushed the add-async-helpers-to-schedulers branch from 4b350b7 to d222a44 Compare November 13, 2022 00:22
@RuiAAPeres RuiAAPeres merged commit 4c595d1 into ReactiveCocoa:master Nov 13, 2022
@p4checo p4checo deleted the add-async-helpers-to-schedulers branch November 14, 2022 09:16
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.

3 participants