TOC Toolkit API - v0.1.0
    Preparing search index...

    Interface Budget

    The resources that one computation may use. A budget stops the run when a charge does not fit, when the time has passed or when the caller cancels. Run the computation inside attempt to receive that stop as a value.

    interface Budget {
        charge(resource: CountedResource, amount?: number): void;
        fits(resource: CountedResource, amount: number): boolean;
        remaining(resource: CountedResource): number;
        consumed(resource: CountedResource): number;
        child(label: string, options?: ChildBudgetOptions): Budget;
        memo<T>(key: ArtifactKey<T>, owner: object, compute: () => T): T;
    }
    Index
    • Uses amount of a resource, one unit by default. A charge that does not fit stops the run and is not recorded. A charge of Resource.WordLength is the length of one word. It fits when the length is at most the limit, and it does not add to earlier charges.

      Parameters

      Returns void

    • Whether a charge of amount would fit. The call charges nothing.

      Parameters

      Returns boolean

    • The effective residual allowance for this counted resource, including ancestor limits.

      Parameters

      Returns number

    • The amount successfully recorded in this scope and its descendants. For Resource.WordLength it is the largest length admitted.

      Parameters

      Returns number

    • Makes a budget for a part of the computation. The charges of the child also count against this budget and every ancestor, so a child never extends its parent. What the child does not use stays available to this budget. The label names the child in an Exhaustion.

      Parameters

      Returns Budget

    • Returns the artifact of key for owner, and computes it on the first request. A root budget and its descendants share one cache. A computation that the budget stops caches nothing.

      Type Parameters

      • T

      Parameters

      Returns T