Skip to content

Commit f1cbfbb

Browse files
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

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ repos:
3333
pass_filenames: false
3434
- id: pytest
3535
name: Pytest
36-
entry: uv run pytest -n auto
36+
entry: uv run pytest -n auto --cov-fail-under=100
3737
types: [python]
3838
language: system
3939
pass_filenames: false

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ integrations
1919
diagram
2020
weighted_transitions
2121
processing_model
22+
invoke
2223
statecharts
2324
api
2425
auto_examples/index

0 commit comments

Comments
 (0)