hatch-surf/node_modules/next/dist/client/components/promise-queue.js
Riley Zhang df378d33ef
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
Merge GitHub main into Gitea repo (allow unrelated histories)
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>
2026-06-25 05:20:46 +02:00

74 lines
2.3 KiB
JavaScript

/*
This is a simple promise queue that allows you to limit the number of concurrent promises
that are running at any given time. It's used to limit the number of concurrent
prefetch requests that are being made to the server but could be used for other
things as well.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "PromiseQueue", {
enumerable: true,
get: function() {
return PromiseQueue;
}
});
class PromiseQueue {
#maxConcurrency;
#runningCount;
#queue;
constructor(maxConcurrency = 5){
this.#maxConcurrency = maxConcurrency;
this.#runningCount = 0;
this.#queue = [];
}
enqueue(promiseFn) {
let taskResolve;
let taskReject;
const taskPromise = new Promise((resolve, reject)=>{
taskResolve = resolve;
taskReject = reject;
});
const task = async ()=>{
try {
this.#runningCount++;
const result = await promiseFn();
taskResolve(result);
} catch (error) {
taskReject(error);
} finally{
this.#runningCount--;
this.#processNext();
}
};
const enqueueResult = {
promiseFn: taskPromise,
task
};
// wonder if we should take a LIFO approach here
this.#queue.push(enqueueResult);
this.#processNext();
return taskPromise;
}
bump(promiseFn) {
const index = this.#queue.findIndex((item)=>item.promiseFn === promiseFn);
if (index > -1) {
const bumpedItem = this.#queue.splice(index, 1)[0];
this.#queue.unshift(bumpedItem);
this.#processNext(true);
}
}
#processNext(forced = false) {
if ((this.#runningCount < this.#maxConcurrency || forced) && this.#queue.length > 0) {
this.#queue.shift()?.task();
}
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=promise-queue.js.map