Erik Vold: Jetpack Pro Tip - setImmediate and clearImmediate |
Do you know about window.setImmediate
or window.clearImmediate
?
Did you know that you can use these now with the Add-on SDK ?
We’ve managed to keep them a little secret, but they are awesome because
setImmediate
is much quicker than setTimeout(fn, 0)
especially if it is used
a lot as it would be if it were in a loop or if it were used recursively. This is well described in
the notes in MDN on window.setImmediate
.
To use these function with the Add-on SDK, do the following:
const { setImmediate, clearImmediate } = require("sdk/timers");
function doStuff() {}
let timerID = setImmediate(doStuff); // to run `doStuff` in the next tick
clearImmediate(timerID) // to cancel `doStuff`
http://work.erikvold.com/jetpack-pro-tip/2014/09/25/setImmediate.html
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |