-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
Implement a scheduledDelayedFunction
#564
Comments
We just hit this problem and ended up creating our own gated way of executing the delayed scheduled functions. But how was this actually resolved? What is the right way to do this? Our attempt: const gateFactory = (s: fc.Scheduler) => {
const scheduledStarter = s.scheduleFunction(async () => {});
return async <T>(f: () => Promise<T>) => {
await scheduledStarter();
return await f();
};
}; Example of how it was used:
|
If I understand well your nee: you attempt to fire the function passed to Given the code you wrote, you may have executions like: gantt
dateFormat HH:mm
axisFormat %H:%M
g1: m1, 00:06, 4min
g2: m2, 00:03, 2min
g3: m3, 00:00, 10min
Note that In other words, it will fire calls to The snippet of const gateFactory = (s: fc.Scheduler) => {
const scheduledStarter = s.scheduleFunction(async (_label: string) => {});
return async <T>(label: string, f: () => Promise<T>) => {
await scheduledStarter(label);
return await f();
};
}; Or just: const gateFactory = (s: fc.Scheduler) => {
return async <T>(label: string, f: () => Promise<T>) => {
await s.schedule(Promise.resolve(label));
return await f();
};
}; |
Yep that's precisely it. We started using your Also I noticed |
So far Regarding the second one, documentation is indeed partially missing. You may want to refer to the examples: https://github.com/dubzzz/fast-check/blob/86164f1b12f010f25fbd16a5acc63bd1c3348dc8/examples/005-race/todolist/main.spec.tsx as https://github.com/dubzzz/fast-check/blob/e7b361ffe13ff22a458d25431788e3caa359646a/packages/fast-check/documentation/RaceConditions.md does not give that much details at the moment. |
I see, but I fee like |
🚀 Feature Request
Similar to
scheduledFunction
but the call to the function itself is also delayed. It is just a syntaxic sugar but it might be used for lots of cases dealing with race conditions.Motivation
Today
scheduledFunction
, barely mimic real worl problem we can have when running asynchronous queries on a distributed environnement. When calling a function wrapped intoscheduledFunction
, the function itself is immediately called. In a context where this function has been mocked, it would be pretty useful to introduce (a scheduled) delay between the moment when the call is triggered and the moment when the call is taken into account by the mock (a bit like a call to server).The text was updated successfully, but these errors were encountered: