Skip to content

Commit

Permalink
Add new Streams API module to v0.51 release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Apr 29, 2024
1 parent 0d27f9b commit 35d0374
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions release notes/v0.51.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,66 @@ k6 `v0.51.0` is here 🎉! This release includes:

_optional intro here_

### `<big_feature_1>` `#pr`
### Introduction of `k6/experimental/streams` module #3696

This release of k6 introduces the new `k6/experimental/streams` module, which partially supports the JavaScript
Streams API, focusing initially on the `ReadableStream` construct.

With the `ReadableStream`, users can define and consume data streams within k6 scripts. This is particularly useful for
efficiently handling large datasets or for processing data sequentially in a controlled flow.

#### Limitations

This initial implementation is an experimental feature and does not include support for the whole Streams API feature set.

Currently, users can define and consume readable streams . However, this release does not include support for byte readers
and controllers, nor does it include support the `tee`, `pipeTo`, and
`pipeThrough` methods of the `ReadableStream` object.

#### Example: streaming numbers

The following example demonstrates creating and consuming a simple stream that emits numbers until it reaches a predfined
limit:

```javascript
import { ReadableStream } from 'k6/experimental/streams'
import { setTimeout } from 'k6/timers'

function numbersStream() {
let currentNumber = 0

return new ReadableStream({
start(controller) {
const fn = () => {
if (currentNumber < 5) {
controller.enqueue(++currentNumber)
setTimeout(fn, 1000)
return;
}

controller.close()
}
setTimeout(fn, 1000)
},
})
}

export default async function () {
const stream = numbersStream()
const reader = stream.getReader()

while (true) {
const { done, value } = await reader.read()
if (done) break
console.log(`received number ${value} from stream`)
}

console.log('we are done')
}
```

For more advanced examples, please head to the MDN Web Docs on the [Streams API](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API).

_what, why, and what this means for the user_

### `<big_feature_n>` `#pr`

Expand Down

0 comments on commit 35d0374

Please sign in to comment.