The .drft container · interface

DrftStreamPacing

When a stream stops to let something else run, and how.

Explained in The .drft container.

interface DrftStreamPacing
import type { DrftStreamPacing } from '@driftengine/drft';

In depth

Why a stream has to stop at all. Once a body's bytes are buffered, every read resolves as a microtask, so a loop that pushes what it reads decodes chunk after chunk inside one task and no frame can draw until the file is done. From a local server a five-file courtyard ran in stretches of 0.6 to 1.1 s and drew 117 frames in five seconds. From a slow network the reads wait, the loop yields there by itself, and this costs nothing.

Both functions are capabilities, for the reason FetchLike is: a host with its own clock or its own scheduler supplies them. What it gives up is throughput when nothing else wants the thread — a task per slice, which a browser may clamp to four milliseconds once timers nest. What would make it wrong is a single chunk longer than the slice, which a slice cannot divide.

Properties

NameTypeDescription
sliceMsreadonlyoptionalnumberWork this long, then give way. DEFAULT_STREAM_SLICE_MS when absent.
nowreadonlyoptional() => numberA monotonic clock in milliseconds. performance.now when absent.
giveWayreadonlyoptional() => Promise<void>Resolve after other tasks have had a turn. A zero-delay timer when absent.