📢 Registration + agenda now live
Explore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).
import{ ReadableStream }from'k6/experimental/streams';import{ setTimeout }from'k6/timers';exportdefaultasyncfunction(){let currentNumber =0;const stream =newReadableStream({start(controller){constfn=()=>{if(currentNumber %8==0){// Close the stream when the number is divisible by 8
controller.close();return;}if(currentNumber <10){
controller.enqueue(++currentNumber);setTimeout(fn,1000);return;}
controller.close();};setTimeout(fn,1000);},});const reader = stream.getReader();while(true){const{ done, value }=await reader.read();if(done)break;
console.log(`received number ${value} from stream`);}}