UNPKG

833 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.nextTick = void 0;
4/**
5 * @name nextTick
6 * @description Defer the operation to the queue for evaluation on the next tick
7 */
8function nextTick(onExec, onError) {
9 // While Promise.resolve().then(...) would defer to the nextTick, this
10 // actually does not play as nicely in browsers like the setTimeout(...)
11 // approach. So the safer, though less optimal approach is the one taken here
12 setTimeout(() => {
13 Promise
14 .resolve()
15 .then(() => {
16 onExec();
17 })
18 .catch((error) => {
19 if (onError) {
20 onError(error);
21 }
22 else {
23 console.error(error);
24 }
25 });
26 }, 0);
27}
28exports.nextTick = nextTick;