Add API for custom time functions implementation
- Dominant language
- TypeScript
- Stars
- 312
- Forks
- 48
- PR merge metrics
- No merged PRs in 30d
Description
## Proposal
Now patronum delay, interval, debounce, time works with global time functions (window.setTimeout, window.setInterval, window.Date.now) what make testing of some features impossible. The solution is create API where developer can manually set implementations of setTimeout/setInterval
Someting like this:
```ts
const $timers = createStore({ setTimeout: (cb) => cb() });
const startDelay = createEvent();
const triggered = delay({ source: startDelay, timeout: 200, timers: $timers });
```
## Motivation
1. Developer can set their own implementations of time functions (this make testing very easy)
2. This solution much better than jest fake timers, 'cause it can't create race condition even in theory
## Related links:
1) [Jest mock race condition](https://github.com/jestjs/jest/issues/8942)
2) [Jest async race condition](https://stackoverflow.com/a/76851759)
Contributor guide
Research direction
Start by reading the patronum delay, interval, debounce, and time implementations, then trace their use of global setTimeout, setInterval, and Date.now. Done means the operators accept supplied time-function implementations and can be tested deterministically without global fake timers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100