Class InMemorySpendDayStore

A store held in memory, for tests and for one process that admits one reservation at a time. It takes no lock, so two admissions awaited at once can both read the same total; a service that admits concurrently implements SpendDayStore on tables whose day row its transaction locks. It holds fenced and operation reservations, and each of its operation methods reads and writes its rows in one step on the event loop, before it awaits anything.

Implements

Constructors

Methods

  • Records a reservation made with requireFence and adds it to its day's open total.

    Parameters

    • reservation: {
          day: string;
          kind: string;
          micro: number;
          created: Date;
          expires: Date;
      }
      • day: string
      • kind: string
      • micro: number
      • created: Date
      • expires: Date

    Returns Promise<string>

  • Records a reservation and adds it to its day's open total.

    Parameters

    • reservation: {
          day: string;
          kind: string;
          micro: number;
          created: Date;
          expires: Date;
          requireFence?: boolean;
      }
      • day: string
      • kind: string
      • micro: number
      • created: Date
      • expires: Date
      • Optional requireFence?: boolean

    Returns Promise<string>

  • Records an operation's row and run 1, or answers null when the operation has one. The check and the record are one synchronous step, so of two admissions of one operation made at once, one records the row.

    Parameters

    • row: {
          day: string;
          kind: string;
          micro: number;
          created: Date;
          expires: Date;
          operation: string;
          runMicro: number;
          leaseUntil: Date;
      }
      • day: string
      • kind: string
      • micro: number
      • created: Date
      • expires: Date
      • operation: string
      • runMicro: number
      • leaseUntil: Date

    Returns Promise<null | string>

  • A run's beginning; the store takes no lock and runs one call at a time on the event loop (see the class).

    Parameters

    • id: string
    • run: {
          runMicro: number;
          leaseUntil: Date;
          maxRuns: number;
          at: Date;
      }
      • runMicro: number
      • leaseUntil: Date
      • maxRuns: number
      • at: Date

    Returns Promise<RunBegin>

  • A lease's renewal by the run that holds it, in one step.

    Parameters

    • id: string
    • renew: {
          run: number;
          leaseUntil: Date;
          at: Date;
      }
      • run: number
      • leaseUntil: Date
      • at: Date

    Returns Promise<boolean>

  • A run's own row, for tests.

    Parameters

    • id: string
    • run: number

    Returns undefined | {
        boundMicro: number;
        settledMicro: null | number;
    }

Properties

fencedReservations: true = ...

It holds fenced reservations.

operationReservations: true = ...

It holds operation reservations.