canjs / can-zone

A context for tracking asynchronous activity in JavaScript applications.
https://v4.canjs.com/doc/can-zone.html
MIT License
92 stars 4 forks source link

setInterval ~13 #78

Open gre opened 8 years ago

gre commented 8 years ago

shouldn't setInterval be wrapped as well?

matthewp commented 8 years ago

Perhaps wrapped, but not wrapped and waited on.

matthewp commented 8 years ago

Fair point though, it should still be run within the Zone.

justinbmeyer commented 8 years ago

Perhaps waited on. It's possible someone starts an interval and then cancels it.

Sent from my iPhone

On May 20, 2016, at 6:24 AM, Matthew Phillips notifications@github.com wrote:

Perhaps wrapped, but not wrapped and waited on.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

matthewp commented 8 years ago

We can't really detect that though. I think it's edge-casey enough to ignore, and people can always use Zone.waitFor themselves for code like this.

justinbmeyer commented 8 years ago

Why can't we? We should be able to detect if someone calls clearTimeout or clearInterval

Sent from my iPhone

On May 20, 2016, at 9:20 AM, Matthew Phillips notifications@github.com wrote:

We can't really detect that though. I think it's edge-casey enough to ignore, and people can always use Zone.waitFor themselves for code like this.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

matthewp commented 8 years ago

Ok so I think you mean code like this:

var id = setInterval(function(){ ... });

clearInterval(id);

Yes, I agree we can support this. We will need to check if it is cleared at end-of-turn or not.

I was thinking something like this, which I don't think we should attempt to detect:

var count = 0;

var id = setInterval(function(){
  if(count === 5) {
    clearInterval(id);
  }

  count++;
}, 500);
matthewp commented 8 years ago

Actually, I'm confused, this scenario:

var id = setInterval(function(){ ... });

clearInterval(id);

We don't need to wait on this anyways. So what scenario that a setInterval is cleared that we should wait on?

justinbmeyer commented 8 years ago

I'm thinking about things like your previous example:

var count = 0;

var id = setInterval(function(){
  if(count === 5) {
    clearInterval(id);
  }

  count++;
}, 500);

Lots of animation libraries use setTimeout / clearTimeout. Poorly written ones might use setInterval clearInterval.

Animations might run while the app is bootstrapping. Maybe someone is using setInterval in some strange way to poll XHR (some ajax libraries polled XHR to avoid memory leaks).

My gut tells me to watch it by default, and then let people turn it off.

matthewp commented 8 years ago

jQuery animate uses setInterval: https://github.com/canjs/can-zone/issues/86

mickmcgrath13 commented 7 years ago

Looks like jQuery ^3.2.0 uses rAF: https://github.com/jquery/jquery/commit/6d43dc42337089f5fb52b715981c12993f490920

frank-dspeed commented 7 years ago

i also use setInterval for polling