-
Notifications
You must be signed in to change notification settings - Fork 107
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 requestIdleCallback
#218
Comments
Hello, I'm interested in solving this issue. Can you guide me, please? |
Hey sure, @shdq - thank you for offering to help!
I estimate this will be about 10 hours of work. Is this something you feel comfortable committing to? (If so, do you feel comfortable committing to in a 2 week timeframe?) |
Also, if any step is unclear (if you want to commit to this which by any means you're not obligated to since it's volunteering your time to open source) - by all means ask about it :) |
It's ok, I have enough time to work on it. I think it will be a lot of questions from me as a newcomer. |
@shdq thanks! I'm removing the "help wanted" label and I welcome the lots of questions you may have 😄 Questions are welcome + it's an opportunity for us to clarify things. |
I did some research about requestidlecallback and tried it. According to wc3 spec idle callbacks algorithm default behaviour of requestIdleCallback without timeout option idle callbacks have "no guarantee" to execute in busy app because user agent may find higher priority work to do and delay them. That's why it has to be used only for non-essential tasks. About timeout option, seems like you should use it only when you really need to, because it can lead to lags and bad user experience if idle task will be executed when where isn't have enough time for it and can affect performance. To find idle period, algorithm has several steps and one of them is to:
So, i think in lolex case requestIdleCallback (without timeout option) should be executed last after all tasks (we consider timers as tasks) and microtasks. What do you think, @benjamingr? |
That sounds good to me 👍 To be clear that implies that If the timeout option exists on the other hand it should run according to that as a timer right? |
Seems odd that if we tick say 1000ms between 2 timers that it's not considered "idle" in between. setTimeout(() => {
console.log('timeout');
}, 500);
requestIdleCallback(() => {
console.log('idle');
});
|
That also works - to be fair I'm more concerned about the case where the timeout is passed in which case we have a real guarantee. |
In native implementation the idle and timeout callbacks are raced and cancel each other – e.g. if the idle callback is scheduled first, then it cancels the timeout callback, and vice versa.
Good point, timeRemaining() for the idle period is 50ms max, so it can be even two idle periods in a row if other important work won't occur. |
Hey, @benjamingr I have a questions about git workflow. I suppose to do this:
Would it be possible to keep committing in this PR? Can I add at least one test and make a WIP PR and keep working in it with your help? About tests. I'm not very familiar with it, in What kind of tests in fourth step? Any help, references? And we still not decided with the behavior of Thank you. |
Yes, you can do that by committing to that branch on your repository.
Sure.
A test there means "test for existence" like an
Sure :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
[WIP] Issue #218 – `requestIdleCallback` implementation
This is an issue for a new contributor to pick up unless someone has an urgent requirement lolex adds this.
requestIdleCallback
isn't implemented in lolex. Since it's timing related - we should probably support it.This ticket is to implement it in lolex (it will be guided if you're new and not sure you can do it!)
**What did you expect to happen?
What actually happens
lolex does not override requestIdleCallback
The text was updated successfully, but these errors were encountered: