feat(rednote): add isolated persistent browser H5 entry

This commit is contained in:
xsl
2026-10-19 22:59:10 +08:00
parent 9eec4369da
commit 4af825a5e4
24 changed files with 707 additions and 45 deletions
+17
View File
@@ -0,0 +1,17 @@
'use strict';
// Rednote-only admission control. Includes JSON consumption in the critical section.
module.exports = function providerGate(fetchImpl, maxPending = 4) {
let tail = Promise.resolve(), pending = 0;
return function (...args) {
if (pending >= maxPending) return Promise.reject(Error('Detection queue is full'));
pending++;
const result = tail.then(async () => {
args[1]?.signal?.throwIfAborted();
const response = await fetchImpl(...args);
const data = await response.json();
return { ok: response.ok, status: response.status, json: async () => data };
});
tail = result.catch(() => {}).finally(() => { pending--; });
return result;
};
};