Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
import { requestIdleCallback } from '../request-idle-callback';
|
|
// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive
|
|
// considers as "Good" time-to-interactive. We must assume something went
|
|
// wrong beyond this point, and then fall-back to a full page transition to
|
|
// show the user something of value.
|
|
const MS_MAX_IDLE_DELAY = 3800;
|
|
/** Resolve a promise that times out after given amount of milliseconds. */ export function resolvePromiseWithTimeout(p, err, devPromise) {
|
|
return new Promise((resolve, reject)=>{
|
|
let cancelled = false;
|
|
p.then((r)=>{
|
|
// Resolved, cancel the timeout
|
|
cancelled = true;
|
|
resolve(r);
|
|
}).catch(reject);
|
|
// We wrap these checks separately for better dead-code elimination in
|
|
// production bundles.
|
|
if (process.env.NODE_ENV === 'development') {
|
|
;
|
|
(devPromise || Promise.resolve()).then(()=>{
|
|
requestIdleCallback(()=>setTimeout(()=>{
|
|
if (!cancelled) {
|
|
reject(err);
|
|
}
|
|
}, MS_MAX_IDLE_DELAY));
|
|
});
|
|
}
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
requestIdleCallback(()=>setTimeout(()=>{
|
|
if (!cancelled) {
|
|
reject(err);
|
|
}
|
|
}, MS_MAX_IDLE_DELAY));
|
|
}
|
|
});
|
|
}
|
|
|
|
//# sourceMappingURL=promise.js.map
|