w3c / requestidlecallback

Cooperative Scheduling of Background Tasks
https://w3c.github.io/requestidlecallback/
Other
50 stars 19 forks source link

It is unclear what IdleDeadline.timeRemaining() should return if JS keeps the IdleDealing object alive even after the callback call. #47

Closed smaug---- closed 7 years ago

smaug---- commented 8 years ago

I assume it should be 0, but the spec language doesn't really capture that case, since there isn't any associated callback anymore at that time.

rmcilroy commented 8 years ago

The implementation in Chrome keeps an absolute deadline time internally in the IdleDeadline object, with timeRemaining() being the relative time between this deadline and performance.now() (with a floor of 0). This means the timeRemaining counts down to this deadline even if after the callback call (and then stays at zero once it reaches it).

It feels like it might be useful to allow the IdleDeadline to continue to keep the deadline even after the callback, but I'm not sure whether we should spec this - it might cause issues for other implementations or limit our future flexibility in updating the deadline if external events arrive. @igrigorik, @toddreifsteck, @bzbarsky any thoughts?

bzbarsky commented 8 years ago

I don't have any thoughts offhand.

smaug---- commented 8 years ago

I don't think it really matters much what is spec'ed here, just that some behavior is spec'ed.

toddreifsteck commented 8 years ago

I agree with @smaug---- . We should either outline future use cases are spec IdleDeadline as well as we can within our current use cases.

igrigorik commented 7 years ago

https://w3c.github.io/requestidlecallback/#the-timeremaining-method

Let timeRemaining be deadline - now. If timeRemaining is negative, set it to 0.

Is this not sufficient? =/

bzbarsky commented 7 years ago

The problem is in step 1 of the algorithm: there is no "associated callback" at that point, so "the deadline of the associated callback" is not defined at all.

igrigorik commented 7 years ago

Ah, ok, I see the confusion. So, in 5.2 (Invoke idle callbacks algorithm) we have..

Let deadlineArg be an IdleDeadline constructed with the given deadline and the didTimeout attribute set to false.

In other words, IdleDeadline has a references to deadline time. Can we just drop step 1 in 4.3 (Let deadline be the..) to clear this up? Alternatively, we could spell it out.. "Lead idledeadline be the DOMHighResTimestamp value of the deadline argument of IdleDeadline", or some such?

rmcilroy commented 7 years ago

Yes this sounds good to me. Dropping step 1 (and also updating the "callback's deadline" with "the deadline argument passed to IdleDeadline" in the paragraph above) would be my preference if it is clear enough to everyone else.

bzbarsky commented 7 years ago

That seems fine, yes.