mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-21 23:48:05 +00:00
25 lines
707 B
JavaScript
25 lines
707 B
JavaScript
/**
|
|
* @name nextTick
|
|
* @description Defer the operation to the queue for evaluation on the next tick
|
|
*/
|
|
export function nextTick(onExec, onError) {
|
|
// While Promise.resolve().then(...) would defer to the nextTick, this
|
|
// actually does not play as nicely in browsers like the setTimeout(...)
|
|
// approach. So the safer, though less optimal approach is the one taken here
|
|
setTimeout(() => {
|
|
Promise
|
|
.resolve()
|
|
.then(() => {
|
|
onExec();
|
|
})
|
|
.catch((error) => {
|
|
if (onError) {
|
|
onError(error);
|
|
}
|
|
else {
|
|
console.error(error);
|
|
}
|
|
});
|
|
}, 0);
|
|
}
|