Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/next/javascript-api/k6-experimental/streams/readablestream/countqueuingstrategy.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/k6-experimental/streams/readablestream/countqueuingstrategy/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
CountQueuingStrategy
The CountQueuingStrategy interface of the Streams API represents a built-in queuing strategy that counts the number of chunks in the queue.
Properties
| Name | Type | Description |
|---|---|---|
| highWaterMark | number | The maximum number of chunks that the queue can contain. |
Example
import { CountQueuingStrategy, ReadableStream } from 'k6/experimental/streams';
import { setTimeout } from 'k6/timers';
export default async function () {
// Define a number stream that emits numbers from 1 to 10 every second
const stream = numbersStream();
// We use the getReader method to create a reader and lock the stream to it
const reader = stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log(`received number ${value} from stream`);
}
}
function numbersStream() {
let currentNumber = 0;
// Using the CountQueuingStrategy to limit the number of chunks in the queue to 5
const queuingStrategy = new CountQueuingStrategy({ highWaterMark: 5 });
return new ReadableStream(
{
start(controller) {
const fn = () => {
if (currentNumber < 10) {
controller.enqueue(++currentNumber);
setTimeout(fn, 1000);
return;
}
controller.close();
};
setTimeout(fn, 1000);
},
},
queuingStrategy
);
}Was this page helpful?
Related resources from Grafana Labs

