ejectamenta
ejectamenta

Reputation: 1087

can webworkers be used to make timing more accurate

If you want to animation this commonly involves calling settimeout or setinterval. The event then joins the other events in the event queuing system and the event may get delayed from the time set when you called the settimeout due to the application GUI processing other events like canvas mouse movements. However what if you set up the animation loop in a webworker? that will not be influenced by GUI events and can accurately call the animation function in the main thread (using postmessage) at the precise time interval set in the function call. Seems ok in theory at least, but would it really work?

Upvotes: 2

Views: 567

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074485

However what if you set up the animation loop in a webworker?

Same problem: The event coming from the web worker that tells you it's time to do something joins the same task queue that setTimeout or setInterval's tasks join.

You might get better results from requestAnimationFrame rather than setTimeout/setInterval, as its express purpose is to increase the synchronization of your code with the browser's display refresh cycle.

Upvotes: 3

Related Questions