Skip to content

Commit

Permalink
[DOCS-2646] Document <stream>.close() method (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodewig authored Apr 5, 2024
1 parent 5905436 commit fb1ad8b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,33 @@ stream.start(
);
```

_Close a stream_

Use the `<stream>.close()` method to close a stream.

```javascript
import { Client, fql } from "fauna"
const client = new Client()

const stream = await client.stream(fql`Product.all().toStream()`)

let count = 0;
for await (const event of stream) {
console.log(event.type)
console.log(event.data)
count++;

// Close the stream after 2 events
if (count === 2) {
console.log("Closing the stream ...")
stream.close()
break;
}
}

client.close();
```

# Contributing

Any contributions are from the community are greatly appreciated!
Expand Down

0 comments on commit fb1ad8b

Please sign in to comment.