liveBook · Manning

Queuing strategy

As explained in JavaScript in Depth

A Web Streams configuration object that determines how queued chunks are measured and how queue limits are applied.

A queuing strategy determines how a ReadableStream measures queued chunks and applies its highWaterMark. CountQueuingStrategy counts JavaScript values; ByteQueuingStrategy counts total bytes. Byte measurement is more predictable when chunks vary from a few bytes to several kilobytes. section 10.4.2

Use the strategy together with desiredSize to interpret backpressure:

  • Positive desiredSize means the queue has room; zero means capacity; a negative value means the queue exceeds its limit. section 10.4.2
  • When desiredSize is zero or negative, the runtime stops calling pull(), provided production remains inside pull(). section 10.4.2
  • Extracting the controller and enqueueing from an independent feed bypasses that protection, allowing an unbounded queue unless the feed is paused or otherwise coordinated. section 10.4.2
const readable = new ReadableStream({
  pull(controller) {
    controller.enqueue(getNextChunk());
  }
}, new CountQueuingStrategy({ highWaterMark: 10 }));  // #A

A CountQueuingStrategy with highWaterMark 10 limits the queue by distinct JavaScript values while pull() supplies chunks. section 10.4.2

How JavaScript in Depth covers it

How deep it goes
Explains count-versus-byte measurement, desiredSize thresholds, and controller-extraction failure, but stops short of full strategy algorithms.
Examples
Uses CountQueuingStrategy with highWaterMark 10 and contrasts pull-based production with independently pushed feed events.
What it assumes
Assumes familiarity with ReadableStream controllers, pull(), enqueue(), and desiredSize.
What you can do after
Operate/configure ReadableStream queues with count- or byte-based limits and recognize when push sources defeat backpressure.
How it connects
Connects queuing strategies with ReadableStream, highWaterMark, desiredSize, pull(), and backpressure.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.