realtime/outbound_budget.ts

The byte budget of the frames waiting to be written to one connection — a WebSocket or an SSE stream.

A producer never waits on a recipient: a broadcast is synchronous and called from anywhere, so a client that stopped reading makes the server hold what it has not taken. OutboundBudget is the bound on that, and it is accounting only — its owner holds the frames and decides what "waiting" means for its connection (WsOutboundWriter for a WebSocket, create_sse_response for an SSE stream).

  • The charge. Each waiting frame is charged its payload bytes — the UTF-8 length of its text — plus OUTBOUND_FRAME_OVERHEAD_BYTES.
  • The rule. A frame is admitted when the charges already waiting plus its own stay within the budget — and, whatever its size, when nothing is waiting, so a single message larger than the whole budget is deliverable.

Nothing counts frames: any number may wait while their charges fit. The twin of the Rust spine's fuz_realtime outbound queue, with the same charge and the same rule.

view source

Declarations
#

3 declarations

OUTBOUND_FRAME_OVERHEAD_BYTES
#

realtime/outbound_budget.ts view source

64 import {OUTBOUND_FRAME_OVERHEAD_BYTES} from '@fuzdev/fuz_app/realtime/outbound_budget.js';

What a waiting frame is charged against its budget on top of its payload bytes.

It stands for what a queued frame costs beyond its text, so a frame with little or no payload is not free: a budget of B never holds more than B divided by this many frames, whatever their size. A fixed charge, not a measurement of memory use. Same value as the Rust spine's constant.

OutboundBudget
#

realtime/outbound_budget.ts view source

import {OutboundBudget} from '@fuzdev/fuz_app/realtime/outbound_budget.js';

The accounting for one connection's waiting frames (module doc).

admit charges a frame that fits, release frees the charge of one that is no longer waiting, and clear frees them all.

max_bytes

The budget, in bytes.

type number

readonly

constructor

type new (max_bytes: number): OutboundBudget

max_bytes

the budget, in bytes; 0 admits one frame at a time

type number

throws

  • Error - when `max_bytes` is not a non-negative safe integer

admit

Charge a frame of frame_bytes payload bytes if it fits: when nothing is waiting, or when the charges waiting plus its own stay within the budget.

type (frame_bytes: number): boolean

frame_bytes

the frame's payload length in UTF-8 bytes

type number
returns boolean

whether the frame was admitted and charged

mutates

  • this — adds the frame's charge when it is admitted

release

Free the charge of one admitted frame that is no longer waiting.

type (frame_bytes: number): void

frame_bytes

the payload length the frame was admitted with

type number
returns void

mutates

  • this — removes the frame's charge

clear

Free every charge — the owner discarded what was waiting.

type (): void

returns void

mutates

  • this — removes every charge

to_overflow

What is waiting, for the log line of a frame that did not fit.

type (frame_bytes: number): OutboundOverflow

frame_bytes

the payload length of the frame that did not fit

type number

queued_bytes

Payload bytes waiting, without the per-frame overhead.

type number

getter

queued_frames

Frames waiting.

type number

getter

OutboundOverflow
#

realtime/outbound_budget.ts view source

OutboundOverflow import type {OutboundOverflow} from '@fuzdev/fuz_app/realtime/outbound_budget.js';

What was waiting when a frame did not fit its connection's budget.

queued_bytes

Payload bytes waiting, without the per-frame overhead the budget also charges.

type number

queued_frames

Frames waiting.

type number

frame_bytes

Payload bytes of the frame that did not fit, without its overhead.

type number

Imported by
#