<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>ReadableStreamDefaultController on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/</link><description>Recent content in ReadableStreamDefaultController on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/index.xml" rel="self" type="application/rss+xml"/><item><title>close()</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/close/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/close/</guid><content><![CDATA[&lt;h1 id=&#34;close&#34;&gt;close()&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;close()&lt;/code&gt; method of the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/&#34;&gt;ReadableStreamDefaultController&lt;/a&gt; interface closes the associated stream.&lt;/p&gt;
&lt;p&gt;Readers can still read any previously enqueued chunks from the stream. Once those chunks are read, the stream closes, and no more data is available.&lt;/p&gt;
&lt;h2 id=&#34;exceptions&#34;&gt;Exceptions&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Exception&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;TypeError&lt;/td&gt;
              &lt;td&gt;Thrown when the source object is not a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/&#34;&gt;ReadableStreamDefaultController&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { ReadableStream } from &amp;#39;k6/experimental/streams&amp;#39;;
import { setTimeout } from &amp;#39;k6/timers&amp;#39;;

export default async function () {
  let currentNumber = 0;

  const stream = new ReadableStream({
    start(controller) {
      const fn = () =&amp;gt; {
        if (currentNumber % 8 == 0) {
          // Close the stream when the number is divisible by 8
          controller.close();
          return;
        }

        if (currentNumber &amp;lt; 10) {
          controller.enqueue(&amp;#43;&amp;#43;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`);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="close">close()&lt;/h1>
&lt;p>The &lt;code>close()&lt;/code> method of the
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/">ReadableStreamDefaultController&lt;/a> interface closes the associated stream.&lt;/p>
&lt;p>Readers can still read any previously enqueued chunks from the stream. Once those chunks are read, the stream closes, and no more data is available.&lt;/p></description></item><item><title>enqueue(chunk)</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/enqueue/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/enqueue/</guid><content><![CDATA[&lt;h1 id=&#34;enqueuechunk&#34;&gt;enqueue(chunk)&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;enqueue()&lt;/code&gt; method of the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/&#34;&gt;ReadableStreamDefaultController&lt;/a&gt; interface enqueues a chunk of data into the associated stream.&lt;/p&gt;
&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;chunk&lt;/td&gt;
              &lt;td&gt;any&lt;/td&gt;
              &lt;td&gt;The chunk of data to enqueue into the stream.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;exceptions&#34;&gt;Exceptions&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Exception&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;TypeError&lt;/td&gt;
              &lt;td&gt;Thrown when the source object is not a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/&#34;&gt;ReadableStreamDefaultController&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { open } from &amp;#39;k6/experimental/fs&amp;#39;;
import { ReadableStream } from &amp;#39;k6/experimental/streams&amp;#39;;

// Open a csv file containing the data to be read
const file = await open(&amp;#39;./data.csv&amp;#39;);

export default async function () {
  let lineReaderState;

  // Define a ReadableStream that reads lines from the file
  // and parses them into objects with name and color properties.
  const fileLinesStream = new ReadableStream({
    // The start function is called when the readable stream is
    // created. In here, you can connect to the data source
    // and perform administrative tasks.
    async start(controller) {
      lineReaderState = {
        buffer: new Uint8Array(1024),
        decoder: new TextDecoder(),
        remaining: &amp;#39;&amp;#39;,
      };
    },

    // The pull function is called repeatedly to get data, while the
    // internal high water mark is not reached.
    async pull(controller) {
      const line = await getNextLine(file, lineReaderState);
      if (line === null) {
        controller.close();
        return;
      }

      const [name, color] = line.split(&amp;#39;,&amp;#39;);
      controller.enqueue({ name, color });
    },
  });

  // Obtain and lock a reader to the stream
  const reader = fileLinesStream.getReader();

  try {
    // Read and process each item from the stream
    while (true) {
      const { done, value } = await reader.read();
      if (done) {
        break;
      }

      console.log(value);
    }
  } catch (error) {
    console.error(&amp;#39;Stream reading failed: &amp;#39;, error);
  }
}

// getNextLine reads the next line from the file and returns it.
//
// It reads the file in chunks and buffers the remaining data
// to handle partial lines. It returns null when there are no
// more lines to read.
async function getNextLine(file, state) {
  while (true) {
    if (state.remaining.includes(&amp;#39;\n&amp;#39;)) {
      const lineEndIndex = state.remaining.indexOf(&amp;#39;\n&amp;#39;);
      const line = state.remaining.substring(0, lineEndIndex).trim();

      state.remaining = state.remaining.substring(lineEndIndex &amp;#43; 1);

      if (line) {
        return line;
      }
    } else {
      const bytesRead = await file.read(state.buffer);
      if (bytesRead === null) {
        // EOF
        state.remaining &amp;#43;= state.decoder.decode();

        if (state.remaining) {
          const finalLine = state.remaining.trim();

          // Clear remaining to signal the end
          state.remaining = &amp;#39;&amp;#39;;

          // Return the last non-empty line
          return finalLine;
        }

        // Indicate that there are no more lines to read
        return null;
      }

      state.remaining &amp;#43;= state.decoder.decode(state.buffer.subarray(0, bytesRead), {
        stream: true,
      });
    }
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="enqueuechunk">enqueue(chunk)&lt;/h1>
&lt;p>The &lt;code>enqueue()&lt;/code> method of the
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/">ReadableStreamDefaultController&lt;/a> interface enqueues a chunk of data into the associated stream.&lt;/p>
&lt;h2 id="parameters">Parameters&lt;/h2>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Name&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>chunk&lt;/td>
&lt;td>any&lt;/td>
&lt;td>The chunk of data to enqueue into the stream.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h2 id="exceptions">Exceptions&lt;/h2>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Exception&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>TypeError&lt;/td>
&lt;td>Thrown when the source object is not a
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/">ReadableStreamDefaultController&lt;/a>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h2 id="example">Example&lt;/h2>
&lt;!-- md-k6:skip -->
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { open } from &amp;#39;k6/experimental/fs&amp;#39;;
import { ReadableStream } from &amp;#39;k6/experimental/streams&amp;#39;;
// Open a csv file containing the data to be read
const file = await open(&amp;#39;./data.csv&amp;#39;);
export default async function () {
let lineReaderState;
// Define a ReadableStream that reads lines from the file
// and parses them into objects with name and color properties.
const fileLinesStream = new ReadableStream({
// The start function is called when the readable stream is
// created. In here, you can connect to the data source
// and perform administrative tasks.
async start(controller) {
lineReaderState = {
buffer: new Uint8Array(1024),
decoder: new TextDecoder(),
remaining: &amp;#39;&amp;#39;,
};
},
// The pull function is called repeatedly to get data, while the
// internal high water mark is not reached.
async pull(controller) {
const line = await getNextLine(file, lineReaderState);
if (line === null) {
controller.close();
return;
}
const [name, color] = line.split(&amp;#39;,&amp;#39;);
controller.enqueue({ name, color });
},
});
// Obtain and lock a reader to the stream
const reader = fileLinesStream.getReader();
try {
// Read and process each item from the stream
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
console.log(value);
}
} catch (error) {
console.error(&amp;#39;Stream reading failed: &amp;#39;, error);
}
}
// getNextLine reads the next line from the file and returns it.
//
// It reads the file in chunks and buffers the remaining data
// to handle partial lines. It returns null when there are no
// more lines to read.
async function getNextLine(file, state) {
while (true) {
if (state.remaining.includes(&amp;#39;\n&amp;#39;)) {
const lineEndIndex = state.remaining.indexOf(&amp;#39;\n&amp;#39;);
const line = state.remaining.substring(0, lineEndIndex).trim();
state.remaining = state.remaining.substring(lineEndIndex &amp;#43; 1);
if (line) {
return line;
}
} else {
const bytesRead = await file.read(state.buffer);
if (bytesRead === null) {
// EOF
state.remaining &amp;#43;= state.decoder.decode();
if (state.remaining) {
const finalLine = state.remaining.trim();
// Clear remaining to signal the end
state.remaining = &amp;#39;&amp;#39;;
// Return the last non-empty line
return finalLine;
}
// Indicate that there are no more lines to read
return null;
}
state.remaining &amp;#43;= state.decoder.decode(state.buffer.subarray(0, bytesRead), {
stream: true,
});
}
}
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>error(reason)</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/error/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/error/</guid><content><![CDATA[&lt;h1 id=&#34;errorreason&#34;&gt;error(reason)&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;error()&lt;/code&gt; method of the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/&#34;&gt;ReadableStreamDefaultController&lt;/a&gt; makes any future interactions with the associated stream to error.&lt;/p&gt;
&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;e&lt;/td&gt;
              &lt;td&gt;any&lt;/td&gt;
              &lt;td&gt;The error to return to any future interactions with the stream.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;exceptions&#34;&gt;Exceptions&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Exception&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;TypeError&lt;/td&gt;
              &lt;td&gt;Thrown when the source object is not a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/&#34;&gt;ReadableStreamDefaultController&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { ReadableStream } from &amp;#39;k6/experimental/streams&amp;#39;;
import { setTimeout } from &amp;#39;k6/timers&amp;#39;;

export default async function () {
  let currentNumber = 0;

  const stream = new ReadableStream({
    start(controller) {
      const fn = () =&amp;gt; {
        if (currentNumber % 8 == 0) {
          // Error the stream when the number is divisible by 8
          controller.error(&amp;#39;erroring the stream because we received a multiple of 8&amp;#39;);
          return;
        }

        if (currentNumber &amp;lt; 10) {
          controller.enqueue(&amp;#43;&amp;#43;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`);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="errorreason">error(reason)&lt;/h1>
&lt;p>The &lt;code>error()&lt;/code> method of the
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/">ReadableStreamDefaultController&lt;/a> makes any future interactions with the associated stream to error.&lt;/p>
&lt;h2 id="parameters">Parameters&lt;/h2>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Name&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>e&lt;/td>
&lt;td>any&lt;/td>
&lt;td>The error to return to any future interactions with the stream.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h2 id="exceptions">Exceptions&lt;/h2>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Exception&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>TypeError&lt;/td>
&lt;td>Thrown when the source object is not a
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/">ReadableStreamDefaultController&lt;/a>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h2 id="example">Example&lt;/h2>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { ReadableStream } from &amp;#39;k6/experimental/streams&amp;#39;;
import { setTimeout } from &amp;#39;k6/timers&amp;#39;;
export default async function () {
let currentNumber = 0;
const stream = new ReadableStream({
start(controller) {
const fn = () =&amp;gt; {
if (currentNumber % 8 == 0) {
// Error the stream when the number is divisible by 8
controller.error(&amp;#39;erroring the stream because we received a multiple of 8&amp;#39;);
return;
}
if (currentNumber &amp;lt; 10) {
controller.enqueue(&amp;#43;&amp;#43;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`);
}
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item></channel></rss>