Products
LGTM+ Stack
Key Capabilities
Observability Solutions
Deploy The Stack
Open Source
Community resources
Dashboard templates
Try out and share prebuilt visualizations
Prometheus exporters
Get your metrics into Prometheus quickly
end-to-end solutions
Opinionated solutions that help you get there easier and faster
monitor infrastructure
Out-of-the-box KPIs, dashboards, and alerts for observability
visualize any data
Instantly connect all your data sources to Grafana
Learn
Stay up to date
Technical learning
Docs
Get started
Get started with Grafana
Build your first dashboard
Get started with Grafana Cloud
What's new / Release notes
Help build the future of open source observability software Open positions
Check out the open source projects we support Downloads
Deploy The Stack
end-to-end solutions
Opinionated solutions that help you get there easier and faster
visualize any data
Instantly connect all your data sources to Grafana
The CountQueuingStrategy
interface of the Streams API represents a built-in queuing strategy that counts the number of chunks in the queue.
Name | Type | Description |
---|---|---|
highWaterMark | number | The maximum number of chunks that the queue can contain. |
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
);
}