Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS-2647] Document <stream>.close() method #175

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,34 @@ _Stream events iterator_

The stream method returns an iterator that can be used to provide the events as they happen. See above examples for using the iterator to process events.

_Close a stream_

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

```python
import fauna

from fauna import fql
from fauna.client import Client

client = Client()

events = []

with client.stream(fql(
'Product.all().where(.price > 50).toStream() { name, price, category }'
)) as stream:
for event in stream:
print(event["type"])
print(event["data"])

events.append(event)
# Close the stream after 2 events
if len(events) == 2:
print("Closing the stream ...")
stream.close()
```

_Error Handling_

If a non retryable error occurs as part of stream processing, or when attempting to open a stream, a FaunaException will be raised. This can be handled as follows:
Expand Down
Loading