Duffer Derek

Current Path : /var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/metro/src/lib/
Upload File :
Current File : /var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/metro/src/lib/debounceAsyncQueue.js

"use strict";

function debounceAsyncQueue(fn, delay) {
  let timeout;
  let waiting = false;
  let executing = false;
  let callbacks = [];
  async function execute() {
    const currentCallbacks = callbacks;
    callbacks = [];
    executing = true;
    const res = await fn();
    currentCallbacks.forEach((c) => c(res));
    executing = false;
    if (callbacks.length > 0) {
      await execute();
    }
  }
  return () =>
    new Promise((resolve, reject) => {
      callbacks.push(resolve);
      if (!executing) {
        if (waiting) {
          clearTimeout(timeout);
        } else {
          waiting = true;
        }
        timeout = setTimeout(async () => {
          waiting = false;
          await execute();
        }, delay);
      }
    });
}
module.exports = debounceAsyncQueue;

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists