Skip to content

Conversation

@p4checo
Copy link
Contributor

@p4checo p4checo commented Jul 22, 2021

The Effect.throttle operator had multiple data races when updating throttleTimes and throttleValues shared state, because:

  1. Effect.throttle can be called from any scheduler.
  2. The internal flatMap runs on the current chain scheduler, but the throttled (delayed) value runs on the passed in scheduler parameter (which can be different).

By protecting shared state with a lock (similar to the cancellables'), these data races should be addressed.

Additionally, the Effect.throttle should return all values in the scheduler passed in, so that the API contract is honored and values come from where callers expect them to.

Changes

  • Add new throttleLock recursive lock to protect throttleTimesandthrottleValuesshared state inEffect.throttle` operator.

  • Ensure all values in Effect.throttle come from the passed in scheduler.

The `Effect.throttle` operator had multiple data races when updating
`throttleTimes` and `throttleValues` shared state, because:

1. `Effect.throttle` can be called from any scheduler.
2. The internal `flatMap` runs on the current chain scheduler, but the
throttled (delayed) value runs on the passed in `scheduler` parameter
(which can be different).

By protecting shared state with a lock (similar to the cancellables'),
these data races should be addressed.

Additionally, the `Effect.throttle` should return all values in the
`scheduler` passed in, so that the API contract is honored and values
come from where callers expect them to.

## Changes

- Add new `throttleLock` `recursive lock to protect `throttleTimes`
and `throttleValues` shared state in `Effect.throttle` operator.

- Ensure all values in `Effect.throttle` come from the passed in
`scheduler`.
@stephencelis
Copy link
Member

@p4checo Thanks for the PR! Looks like the changes are breaking our test expectations. Can you look into what may have changed?

@p4checo p4checo requested a review from stephencelis July 22, 2021 16:17
@stephencelis stephencelis merged commit 65f1fa0 into pointfreeco:main Jul 22, 2021
@p4checo p4checo deleted the fix-effect-throttle-data-races-and-scheduler-value-return branch July 22, 2021 17:33
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