Commit f1cbfbb
authored
feat: invoke callback group — spawn external work from states (#571)
* feat: invoke callback group — spawn external work from states
Add invoke as a first-class callback group (CallbackGroup.INVOKE), following
SCXML <invoke> semantics. States can spawn background work (API calls, file I/O,
child state machines) on entry and cancel it on exit.
- New CallbackGroup.INVOKE with convention naming (on_invoke_<state>),
decorator (@state.invoke), and inline callables
- IInvoke protocol for advanced handlers with InvokeContext (cancellation,
send events to parent, machine reference)
- StateChartInvoker adapter for child state machine invocation
- invoke_group() for running multiple callables concurrently and waiting
for all results as a single done.invoke event
- InvokeManager lifecycle management integrated into both sync and async engines
(sync: daemon threads, async: thread executor wrapped in asyncio.Task)
- done_invoke_<state> factory prefix maps to done.invoke.<state> event family
- visitor pattern (visit/async_visit) on CallbacksExecutor and CallbacksRegistry
- __contains__ on CallbacksRegistry to avoid direct _registry access
- Full test suite and documentation with practical file I/O examples
- Plain callables receive kwargs via SignatureAdapter dependency injection
- IInvoke handlers receive kwargs via ctx.kwargs
This allows patterns like sm.send("start", file_name="config.json")
where the invoke handler reads file_name as a parameter.1 parent 3b5ef35 commit f1cbfbb
15 files changed
Lines changed: 2075 additions & 7 deletions
File tree
- docs
- releases
- statemachine
- engines
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
0 commit comments