Skip to content

Commit ac574c8

Browse files
committed
Finalize docs.
1 parent d6bcfd7 commit ac574c8

File tree

1 file changed

+49
-55
lines changed

1 file changed

+49
-55
lines changed

README.md

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,24 @@ async for event in client.read_events(
220220

221221
If you need to abort reading use `break` or `return` within the `async for` loop. However, this only works if there is currently an iteration going on.
222222

223-
To abort reading independently of that, hand over an abort signal as third argument when calling `read_events`, and abort the appropriate `AbortController`:
223+
To abort reading independently of that, store the generator in a variable, and close it explicitly:
224224

225225
```python
226226
from eventsourcingdb import ReadEventsOptions
227227

228-
async with client.read_events(
228+
events = client.read_events(
229229
subject = '/books/42',
230230
options = ReadEventsOptions(
231231
recursive = False,
232232
),
233-
) as events:
234-
async for event in events:
235-
pass
233+
)
236234

237-
# Somewhere else, abort the controller, which will cause
238-
# reading to end.
239-
abort()
235+
async for event in events:
236+
pass
240237

241-
# TODO: Fix this section, also the text above.
238+
# Somewhere else, abort the generator, which will cause
239+
# reading to end.
240+
await events.aclose()
242241
```
243242

244243
### Running EventQL Queries
@@ -261,23 +260,22 @@ async for row in client.run_eventql_query(
261260

262261
If you need to abort a query use `break` or `return` within the `async for` loop. However, this only works if there is currently an iteration going on.
263262

264-
To abort the query independently of that, hand over an abort signal as second argument when calling `run_eventql_query`, and abort the appropriate AbortController:
263+
To abort the query independently of that, store the generator in a variable, and close it explicitly:
265264

266265
```python
267-
# const controller = new AbortController();
268-
269-
# for await (const row of client.runEventQlQuery(`
270-
# FROM e IN events
271-
# PROJECT INTO e
272-
# `, controller.signal)) {
273-
# // ...
274-
# }
266+
rows = client.run_eventql_query(
267+
query = '''
268+
FROM e IN events
269+
PROJECT INTO e
270+
''',
271+
)
275272

276-
# // Somewhere else, abort the controller, which will cause
277-
# // the query to end.
278-
# controller.abort();
273+
async for row in rows:
274+
pass
279275

280-
# TODO: Fix this section, also the text above.
276+
# Somewhere else, abort the generator, which will cause
277+
# the query to end.
278+
await rows.aclose()
281279
```
282280

283281
### Observing Events
@@ -372,22 +370,24 @@ async for event in client.observe_events(
372370

373371
If you need to abort observing use `break` or `return` within the `async for` loop. However, this only works if there is currently an iteration going on.
374372

375-
To abort observing independently of that, hand over an abort signal as third argument when calling `observeEvents`, and abort the appropriate `AbortController`:
373+
To abort observing independently of that, store the generator in a variable, and close it explicitly:
376374

377375
```python
378-
# const controller = new AbortController();
376+
from eventsourcingdb import ObserveEventsOptions
379377

380-
# for await (const event of client.observeEvents('/books/42', {
381-
# recursive: false
382-
# }, controller.signal)) {
383-
# // ...
384-
# }
378+
events = client.observe_events(
379+
subject = '/books/42',
380+
options = ObserveEventsOptions(
381+
recursive = False
382+
),
383+
)
385384

386-
# // Somewhere else, abort the controller, which will cause
387-
# // observing to end.
388-
# controller.abort();
385+
async for event in events:
386+
pass
389387

390-
# TODO: Fix example above.
388+
# Somewhere else, abort the generator, which will cause
389+
# observing to end.
390+
await events.aclose()
391391
```
392392

393393
### Registering an Event Schema
@@ -438,22 +438,19 @@ async for subject in client.read_subjects(
438438

439439
If you need to abort listing use `break` or `return` within the `async for` loop. However, this only works if there is currently an iteration going on.
440440

441-
To abort listing independently of that, hand over an abort signal as second argument when calling `readSubjects`, and abort the appropriate `AbortController`:
441+
To abort listing independently of that, store the generator in a variable, and close it explicitly:
442442

443443
```python
444-
# const controller = new AbortController();
445-
446-
# for await (const subject of client.readSubjects(
447-
# '/', controller.signal)
448-
# ) {
449-
# // ...
450-
# }
444+
subjects = client.read_subjects(
445+
base_subject = '/books'
446+
)
451447

452-
# // Somewhere else, abort the controller, which will cause
453-
# // reading to end.
454-
# controller.abort();
448+
async for subject in subjects:
449+
pass
455450

456-
# TODO: Fix the above section.
451+
# Somewhere else, abort the generator, which will cause
452+
# reading to end.
453+
await subjects.aclose()
457454
```
458455

459456
### Listing Event Types
@@ -469,20 +466,17 @@ async for event_type in client.read_event_types():
469466

470467
If you need to abort listing use `break` or `return` within the `async for` loop. However, this only works if there is currently an iteration going on.
471468

472-
To abort listing independently of that, hand over an abort signal as argument when calling `readEventTypes`, and abort the appropriate `AbortController`:
469+
To abort listing independently of that, store the generator in a variable, and close it explicitly:
473470

474471
```python
475-
# const controller = new AbortController();
472+
event_types = client.read_event_types()
476473

477-
# for await (const eventType of client.readEventTypes()) {
478-
# // ...
479-
# }
480-
481-
# // Somewhere else, abort the controller, which will cause
482-
# // reading to end.
483-
# controller.abort();
474+
async for event_type in event_types:
475+
pass
484476

485-
# TODO: Fix the section above.
477+
# Somewhere else, abort the generator, which will cause
478+
# reading to end.
479+
await event_types.aclose()
486480
```
487481

488482
### Using Testcontainers

0 commit comments

Comments
 (0)