Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Guarantee util.throttle delay #360

Merged
merged 3 commits into from
Nov 3, 2017
Merged

Conversation

edhager
Copy link
Contributor

@edhager edhager commented Oct 30, 2017

setTimeout in Edge and IE 11 do not guarantee the delay value. In my testing, if the delay is greater than 200ms, then setTimeout is reliable but with a smaller delay, the callback function can fire early roughly 50% of the time.

I created util.guaranteeMinimumTimeout() which makes sure the desired amount of time has passed.

Fixes: #357

…ack will fire is less amount of time. Modify util.throttle and util.debounce so the delay is always guaranteed.
let timer: Handle | null;

return {
afterEach() {
Copy link
Member

Choose a reason for hiding this comment

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

Is this (and the ones below) needed with the suite-level afterEach()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it.

src/util.ts Outdated
if (delay == null || delta >= delay) {
callback();
} else {
timerId = setTimeout(timeoutHandler);
Copy link
Member

Choose a reason for hiding this comment

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

Should this pass delay - delta as the second argument to setTimeout()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I goofed that when I changed it to make delay optional. I'll fix it.

@edhager
Copy link
Contributor Author

edhager commented Oct 31, 2017

The test failure "Attempt to detect unregistered has feature "web-worker-xhr-upload" is addressed in another ticket/PR: PR #361

@edhager edhager dismissed bryanforbes’s stale review November 1, 2017 20:46

All of Bryan's suggestions have been implemented.

@maier49 maier49 mentioned this pull request Nov 3, 2017
3 tasks
@edhager edhager requested review from maier49 and rorticus and removed request for agubler and maier49 November 3, 2017 15:13
src/util.ts Outdated
} else {
// Cast setTimeout return value to fix TypeScript parsing bug. Without it,
// it thinks we are using the Node version of setTimeout.
timerId = <any> setTimeout(timeoutHandler, delta);
Copy link
Contributor

@maier49 maier49 Nov 3, 2017

Choose a reason for hiding this comment

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

Should we be timing out for delay - delta? What we're saying here is that we want to wait as long as we've waited right? That seems arbitrary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing now...

Copy link
Contributor

@rorticus rorticus left a comment

Choose a reason for hiding this comment

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

Approved after @maier49 's comment is addressed!

@edhager edhager merged commit e987183 into dojo:master Nov 3, 2017
@edhager edhager deleted the throttle-test-357 branch November 3, 2017 16:01
@dylans dylans added this to the beta.4 milestone Dec 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants