{"version":3,"sources":["jsdelivr-header.js","/npm/promise-wait-until@1.0.0/src/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,aCLA,IAAA,gBAAA,QAAA,qB,iIAWA,SAAS,UAAU,EAAmB,EAAkB,GAAI,GAC1D,OAAO,IAAI,SAAQ,CAAC,EAAS,KAE3B,IAAI,EAAQ,KACZ,MAAM,EAAU,EAAU,KAAK,OAAS,EAAQ,KAAO,EAAQ,KAAO,QAAW,EACjF,SAAS,EAAM,IACb,EAAA,iBAAA,SAAe,GAAmB,CAAC,EAAK,IAClC,EACK,EAAO,GACL,EAAO,OACT,EAAQ,EAAO,YAExB,KAEH,CAED,GAAM,KACJ,EAAQ,YAER,SAAS,IACP,GAAI,GAAW,GAAW,KAAK,MAC7B,OAAO,EAAO,IAAI,MACf,EAAQ,QAAU,EAAQ,QAAU,aACrC,YAIJ,GAAM,KACJ,EAAQ,WAAW,EAAc,EAAjC,GAEH,GAbgC,EAahC,GAdH,GAiBH,CAED,OAAO,QAAU","file":"/npm/promise-wait-until@1.0.0/dist/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/promise-wait-until@1.0.0/dist/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* eslint-disable no-use-before-define */\nimport checkCondition from './check-condition';\n\n/**\n * @typedef {function.<(Promise.<any>|any)>} ConditionFunction\n */\n\n/**\n * @param {ConditionFunction} conditionFunction - Checker function.\n * @param {number} [intervalTimeout=50] - Interval to invoke conditionFunction.\n * @param {(number|{ time: number, message: string })?} timeout - Timeout to check.\n */\nfunction waitUntil(conditionFunction, intervalTimeout = 50, timeout) {\n  return new Promise((resolve, reject) => {\n    // eslint-disable-next-line no-unused-vars\n    let timer = null;\n    const endTime = timeout ? Date.now() + (timeout.time ? timeout.time : timeout) : undefined;\n    function check(callback) {\n      checkCondition(conditionFunction, (err, result) => {\n        if (err) {\n          return reject(err);\n        } else if (result.isTrue) {\n          return resolve(result.value);\n        }\n        callback();\n      });\n    }\n\n    check(() => {\n      timer = setTimeout(timerChecker, intervalTimeout);\n\n      function timerChecker() {\n        if (endTime && endTime <= Date.now()) {\n          return reject(new Error(\n            (timeout.message ? timeout.message : 'Time is up'),\n            'TIMEOUT',\n          ));\n        }\n\n        check(() => {\n          timer = setTimeout(timerChecker, intervalTimeout);\n        });\n      }\n    });\n  });\n}\n\nmodule.exports = waitUntil;\n"]}