UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

19 lines (18 loc) 538 B
/** * A decorator utility to postpone callback execution once after the main task execution * (as a microtask produced with Promise) */ export function microtask(fn, thisArg) { let args = []; return function microtaskFn(arg) { if (arguments.length) args.push(arg); if (microtaskFn.request) return; microtaskFn.request = Promise.resolve().then(() => { delete microtaskFn.request; fn.call(thisArg || this, args); args = []; }); }; }