javascript - Understanding JS setTimeout, canvas and "Show paint rectangles" in Google Chrome -
i have question in regards settimeout, , "show paint rectangles" in developer console. in application calls issued through settimeout @ intervals of 48ms draw on canvas quite heavily, , pretty close mark. however, when enable "show paint rectangles" settimeout calls delayed quite significantly, upto 100ms late. hypothesizing due additional drawing performed "show paint rectangles" settimeout calls delayed due single threaded nature of js. hoping either confirm, or deny hypothesis.
the delays cause serious problems application, because there logic in there relies on stability of timeouts - once become unstable drawing buffers flushed, , user faced inconsistent behavior.
what seeing result of race condition. timeouts asynchronous , there no guarantees fire @ times specify (think it, if processor becomes busy or fire off 1000 timeouts has yield).
you can use promises in javascript solution sort of problem:
http://www.html5rocks.com/en/tutorials/es6/promises/
this allows sync tasks waiting until task complete before action fires. more robust trying rely on times.
Comments
Post a Comment