wiresjs / async-watch

AsyncWatch - watching js objects asynchronously
GNU General Public License v3.0
17 stars 3 forks source link

Different result at different times! #10

Open samad-aghaei opened 7 years ago

samad-aghaei commented 7 years ago

I just got different result at different times on example below:

var obj = {}; // creating an empty object AsyncWatch(obj, 'a.b.c', function(value){ console.log('set', value); });

obj.a = { b : { c : 1 } }; obj.a.b.c = 2; obj.a.b.c = 3;

setTimeout(function(){ obj.a.b.c = 4; },10)

/** By holding "CTRL + R" in latest version of Chrome: //Sometimes the result is set 4

//Sometimes the result is set 4 set 4

//Sometimes the result is set 3 set 4

//Sometimes the result is set 3

nchanged commented 7 years ago

@samad-aghaei Hi! I guess that's related to requestAnimationFrame it's rather random ;-) You could suggest an option where this one is setTimeout 0

samad-aghaei commented 7 years ago

@nchanged Thanks for your quick respond. Your'e right, the problem is requestAnimationFrame and I just replace line 3 with the following:

var nextTick = isNode ? process.nextTick : function(frame){return setTimeout(frame, 1000/60)}

It works, Anyway. But I believe that this is not a good solution.

nchanged commented 7 years ago

I believe holding refresh interrupts the execution, and that's why you have inconsistent results

devmondo commented 7 years ago

Some stuff happens asynchronously in the browser, even when you refresh! and they get queued by chrome itself. this is why you sometimes get different results.