UNPKG

706 BJavaScriptView Raw
1/**
2 * @name nextTick
3 * @description Defer the operation to the queue for evaluation on the next tick
4 */
5export function nextTick(onExec, onError) {
6 // While Promise.resolve().then(...) would defer to the nextTick, this
7 // actually does not play as nicely in browsers like the setTimeout(...)
8 // approach. So the safer, though less optimal approach is the one taken here
9 setTimeout(() => {
10 Promise
11 .resolve()
12 .then(() => {
13 onExec();
14 })
15 .catch((error) => {
16 if (onError) {
17 onError(error);
18 }
19 else {
20 console.error(error);
21 }
22 });
23 }, 0);
24}
\No newline at end of file