{"version":3,"sources":["../../../src/client/lib/promise.ts"],"sourcesContent":["import { requestIdleCallback } from '../request-idle-callback'\n\n// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive\n// considers as \"Good\" time-to-interactive. We must assume something went\n// wrong beyond this point, and then fall-back to a full page transition to\n// show the user something of value.\nconst MS_MAX_IDLE_DELAY = 3800\n\n/** Resolve a promise that times out after given amount of milliseconds. */\nexport function resolvePromiseWithTimeout<T>(\n  p: Promise<T>,\n  err: Error,\n  devPromise: Promise<void> | undefined\n): Promise<T> {\n  return new Promise((resolve, reject) => {\n    let cancelled = false\n\n    p.then((r) => {\n      // Resolved, cancel the timeout\n      cancelled = true\n      resolve(r)\n    }).catch(reject)\n\n    // We wrap these checks separately for better dead-code elimination in\n    // production bundles.\n    if (process.env.NODE_ENV === 'development') {\n      ;(devPromise || Promise.resolve()).then(() => {\n        requestIdleCallback(() =>\n          setTimeout(() => {\n            if (!cancelled) {\n              reject(err)\n            }\n          }, MS_MAX_IDLE_DELAY)\n        )\n      })\n    }\n\n    if (process.env.NODE_ENV !== 'development') {\n      requestIdleCallback(() =>\n        setTimeout(() => {\n          if (!cancelled) {\n            reject(err)\n          }\n        }, MS_MAX_IDLE_DELAY)\n      )\n    }\n  })\n}\n"],"names":["resolvePromiseWithTimeout","MS_MAX_IDLE_DELAY","p","err","devPromise","Promise","resolve","reject","cancelled","then","r","catch","process","env","NODE_ENV","requestIdleCallback","setTimeout"],"mappings":";;;;+BASgBA;;;eAAAA;;;qCAToB;AAEpC,uEAAuE;AACvE,yEAAyE;AACzE,2EAA2E;AAC3E,oCAAoC;AACpC,MAAMC,oBAAoB;AAGnB,SAASD,0BACdE,CAAa,EACbC,GAAU,EACVC,UAAqC;IAErC,OAAO,IAAIC,QAAQ,CAACC,SAASC;QAC3B,IAAIC,YAAY;QAEhBN,EAAEO,IAAI,CAAC,CAACC;YACN,+BAA+B;YAC/BF,YAAY;YACZF,QAAQI;QACV,GAAGC,KAAK,CAACJ;QAET,sEAAsE;QACtE,sBAAsB;QACtB,IAAIK,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;;YACxCV,CAAAA,cAAcC,QAAQC,OAAO,EAAC,EAAGG,IAAI,CAAC;gBACtCM,IAAAA,wCAAmB,EAAC,IAClBC,WAAW;wBACT,IAAI,CAACR,WAAW;4BACdD,OAAOJ;wBACT;oBACF,GAAGF;YAEP;QACF;QAEA,IAAIW,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1CC,IAAAA,wCAAmB,EAAC,IAClBC,WAAW;oBACT,IAAI,CAACR,WAAW;wBACdD,OAAOJ;oBACT;gBACF,GAAGF;QAEP;IACF;AACF","ignoreList":[0]}