Skip to content

Commit 7cc1726

Browse files
fgmacedoclaude
andcommitted
docs: rename quickstart to tutorial, add is_terminated section
Rename quickstart.md → tutorial.md and update title to "Tutorial" to distinguish the progressive learning guide from the README showcase. Add "Checking completion with is_terminated" section after parallel states, explaining why is_terminated matters for compound/parallel structures and showing the idiomatic queue-consumption loop pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 713b5ac commit 7cc1726

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Contents:
88
99
readme
1010
installation
11-
quickstart
11+
tutorial
1212
```
1313

1414
```{toctree}
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Quickstart
2+
# Tutorial
33

44
This tutorial walks you through python-statemachine from your first flat state
55
machine all the way to full statecharts — compound states, parallel regions,
@@ -370,11 +370,11 @@ Then generate an image at runtime:
370370
... pick_up = ready.to(picked_up)
371371

372372
>>> order = CoffeeOrder()
373-
>>> order._graph().write_png("docs/images/quickstart_coffeeorder.png")
373+
>>> order._graph().write_png("docs/images/tutorial_coffeeorder.png")
374374

375375
```
376376

377-
![CoffeeOrder](images/quickstart_coffeeorder.png)
377+
![CoffeeOrder](images/tutorial_coffeeorder.png)
378378

379379
Or from the command line:
380380

@@ -499,6 +499,10 @@ True
499499
processes events independently. The machine only transitions out when
500500
**every** region reaches a final state.
501501

502+
503+
504+
### Checking completion with `is_terminated`
505+
502506
In a flat state machine, checking whether you've reached a specific
503507
final state is enough. But with compound and parallel states, completion
504508
depends on the structure — all regions of a parallel must finish, nested
@@ -507,6 +511,26 @@ compounds must reach their own final children, and so on. The
507511
when the entire machine has completed its work, regardless of how deeply
508512
nested the structure is. Use it instead of checking individual states.
509513

514+
A common pattern is to consume events from a queue or stream, feeding
515+
them to the machine until it terminates:
516+
517+
```py
518+
>>> from collections import deque
519+
520+
>>> order = CoffeeOrder()
521+
>>> queue = deque(["start", "brew", "heat"])
522+
523+
>>> while not order.is_terminated and queue:
524+
... order.send(queue.popleft())
525+
526+
>>> order.is_terminated
527+
True
528+
529+
```
530+
531+
This decouples event production from consumption — the queue could come
532+
from a message broker, a file, user input, or any other source.
533+
510534

511535
### History states: remember where you left off
512536

0 commit comments

Comments
 (0)