mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 21:53:51 +00:00
refactor(domain): charge resource allowances through one Budget owner (#11293)
This commit is contained in:
1 parent
c931ba43ab
commit
3d67404132
11 files changed
+215
-96
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { Budget } from "../domain/budget.js";
|
||||
import {
|
||||
noRuntimeOverrideSentence,
|
||||
selectedCdpCommandTimeoutMs,
|
||||
@@ -19,7 +20,7 @@ export const cdpScriptSourceDeadlineOmissionReason = (
|
||||
export class CdpScriptSourceBudget {
|
||||
readonly #deadline: ProviderStartupDeadline;
|
||||
readonly commandTimeoutMs: number;
|
||||
#retainedBytes = 0;
|
||||
readonly #retained = new Budget(WEB_RUNTIME_LIMITS.sourceBytes);
|
||||
|
||||
constructor(
|
||||
signal?: AbortSignal,
|
||||
@@ -39,11 +40,7 @@ export class CdpScriptSourceBudget {
|
||||
|
||||
/** Admit exact UTF-8 source bytes before building or retaining its artifact. */
|
||||
admit(text: string): boolean {
|
||||
const bytes = Buffer.byteLength(text, "utf8");
|
||||
if (bytes > WEB_RUNTIME_LIMITS.sourceBytes - this.#retainedBytes)
|
||||
return false;
|
||||
this.#retainedBytes += bytes;
|
||||
return true;
|
||||
return this.#retained.tryCharge(Buffer.byteLength(text, "utf8"));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
Reference in new issue
Block a user