-
Notifications
You must be signed in to change notification settings - Fork 58
Conversation
…ack will fire is less amount of time. Modify util.throttle and util.debounce so the delay is always guaranteed.
tests/unit/util.ts
Outdated
let timer: Handle | null; | ||
|
||
return { | ||
afterEach() { |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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.
The test failure "Attempt to detect unregistered has feature "web-worker-xhr-upload" is addressed in another ticket/PR: PR #361 |
All of Bryan's suggestions have been implemented.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing now...
There was a problem hiding this 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!
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