Skip to content

Commit 1b5aa7a

Browse files
committed
docs: update readmes v0.12
1 parent c97977b commit 1b5aa7a

File tree

7 files changed

+103
-33
lines changed

7 files changed

+103
-33
lines changed

FAQ.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ aRPC auto syncs only clock values, which technically is `[n]uint64` (`n` = numbe
5252

5353
## Does asyncmachine return data?
5454

55-
No, just yes/no/later (`Executed`, `Canceled`, `Queued`).
55+
No, just yes/no/later (`Executed`, `Canceled`, `Queued`). Use channels in mutation args for returning local data and the `SendPayload` state for aRPC.
5656

5757
## Does asyncmachine return errors?
5858

@@ -73,6 +73,10 @@ The queue executes on the thread which caused the mutation, while handlers execu
7373
Each handler usually forks another goroutine to unblock the next handler. The amount of active goroutines can be limited
7474
with `amhelp.Pool` (`errgroup`) per a state, machine, or both. It's a form of structured concurrency.
7575

76+
## What should be a "state"?
77+
78+
Only interesting things - if we don't care about something to be a separate entity, there's no need to orchestrate it as a separate state.
79+
7680
## What's the origin of asyncmachine?
7781

7882
It was a [self-research prototype](https://github.com/TobiaszCudnik/asyncmachine) between 2012 and 2019. There's a

README.md

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<a href="#samples">Samples</a> .
1313
<a href="#getting-started">Getting Started</a> .
1414
<a href="#packages">Packages</a> .
15+
<a href="#devtools">Devtools</a> .
1516
<a href="#apps">Apps</a> .
1617
<a href="#documentation">Docs</a> .
1718
<a href="#development">Dev</a> .
@@ -28,13 +29,14 @@
2829
</div>
2930

3031
> [!NOTE]
31-
> State machines communicate through states (mutations, checking, and waiting).
32+
> State machines communicate through states.
3233
3334
**asyncmachine-go** is a batteries-included graph control flow library implementing [AOP](https://en.wikipedia.org/wiki/Aspect-oriented_programming)
3435
and [Actor Model](https://en.wikipedia.org/wiki/Actor_model) through a **[clock-based state-machine](/pkg/machine/README.md)**.
35-
It features [atomic transitions](/docs/manual.md#transition-lifecycle), [transparent RPC](/pkg/rpc/README.md),
36-
[TUI debugger](/tools/cmd/am-dbg/README.md), [telemetry](/pkg/telemetry/README.md), [REPL](/tools/cmd/arpc/README.md),
37-
[remote workers](/pkg/node/README.md), and [diagrams](https://github.com/pancsta/asyncmachine-go/pull/216).
36+
It features [atomic transitions](/docs/manual.md#transition-lifecycle), [relations with consensus](/docs/manual.md#relations),
37+
[transparent RPC](/pkg/rpc/README.md), [TUI debugger](/tools/cmd/am-dbg/README.md),
38+
[telemetry](/pkg/telemetry/README.md), [REPL](/tools/cmd/arpc/README.md), [remote workers](/pkg/node/README.md),
39+
and [diagrams](https://github.com/pancsta/asyncmachine-go/pull/216).
3840

3941
As a control flow library, it decides about running of predefined bits of code (transition handlers) - their order and
4042
which ones to run, according to currently active states (flags). Thanks to a [novel state machine](/pkg/machine/README.md),
@@ -53,17 +55,20 @@ It aims to create **autonomous** workflows with **organic** control flow and **s
5355
Each state represents:
5456

5557
- binary flag
56-
- node in a multigraph
58+
- ID
59+
- node with relations
5760
- AOP aspect
58-
- metric
59-
- trace
61+
- logical clock
6062
- subscription topic
6163
- multiple methods
64+
- metric
65+
- trace
66+
- lock
6267
- breakpoint
6368

6469
Besides workflows, it can be used for **stateful applications** of any size - daemons, UIs, configs, bots, firewalls,
65-
synchronization consensus, games, smart graphs, microservice orchestration, contracts, simulators, as well as
66-
**"real-time" systems** which rely on instant cancellations.
70+
synchronization consensus, games, smart graphs, microservice orchestration, robots, contracts, streams, DI containers,
71+
test scenarios, simulators, as well as **"real-time" systems** which rely on instant cancelation.
6772

6873
![diagram](https://github.com/pancsta/assets/blob/main/asyncmachine-go/am-vis.svg?raw=true)
6974

@@ -79,63 +84,99 @@ The top layers depend on the bottom ones.
7984
<td>.</td>
8085
<td>.</td>
8186
<td>.</td>
87+
<td>.</td>
88+
<td>.</td>
8289
<td colspan="1" align=center><a href="pkg/pubsub/README.md">PubSub</a></td>
8390
<td>.</td>
8491
<td>.</td>
8592
<td>.</td>
8693
<td>.</td>
8794
<td>.</td>
8895
<td>.</td>
96+
<td>.</td>
97+
<td>.</td>
98+
<td>.</td>
8999
</tr>
100+
90101
<tr>
91102
<td>.</td>
92103
<td>.</td>
93104
<td>.</td>
94105
<td>.</td>
95106
<td>.</td>
107+
<td>.</td>
108+
<td>.</td>
96109
<td colspan="3" align=center><a href="pkg/node/README.md">Workers</a></td>
97110
<td>.</td>
98111
<td>.</td>
99112
<td>.</td>
100113
<td>.</td>
101114
<td>.</td>
115+
<td>.</td>
116+
<td>.</td>
117+
<td>.</td>
102118
</tr>
119+
103120
<tr>
104121
<td>.</td>
105122
<td>.</td>
106123
<td>.</td>
107124
<td>.</td>
125+
<td>.</td>
126+
<td>.</td>
108127
<td colspan="5" align=center><a href="pkg/rpc/README.md">RPC</a></td>
109128
<td>.</td>
110129
<td>.</td>
111130
<td>.</td>
112131
<td>.</td>
132+
<td>.</td>
133+
<td>.</td>
113134
</tr>
135+
114136
<tr>
137+
<td>.</td>
138+
<td>.</td>
115139
<td>.</td>
116140
<td>.</td>
117141
<td>.</td>
118142
<td colspan="7" align=center><a href="pkg/machine/README.md#aop-handlers">Handlers</a></td>
119143
<td>.</td>
120144
<td>.</td>
121145
<td>.</td>
146+
<td>.</td>
147+
<td>.</td>
122148
</tr>
149+
123150
<tr>
151+
<td>.</td>
152+
<td>.</td>
124153
<td>.</td>
125154
<td>.</td>
126155
<td colspan="9" align=center>🐇 <a href="pkg/machine/README.md">Machine API</a></td>
127156
<td>.</td>
128157
<td>.</td>
158+
<td>.</td>
159+
<td>.</td>
129160
</tr>
161+
130162
<tr>
163+
<td>.</td>
164+
<td>.</td>
131165
<td>.</td>
132166
<td colspan="11" align=center><a href="pkg/machine/README.md#relations">Relations</a></td>
133167
<td>.</td>
168+
<td>.</td>
169+
<td>.</td>
134170
</tr>
171+
135172
<tr>
173+
<td>.</td>
174+
<td>.</td>
136175
<td colspan="13" align=center><a href="pkg/machine/README.md#multi-state"><b><u>
137176
States
138177
</u></b></a></td>
178+
<td>.</td>
179+
<td>.</td>
139180
</tr>
140181
</table>
141182

@@ -254,31 +295,34 @@ All examples and benchmarks can be found in [`/examples`](/examples/README.md).
254295
- 🦾 **[`/pkg/machine`](pkg/machine/README.md)** is the main package
255296
- [`/pkg/node`](pkg/node) shows a high-level usage
256297
- examples in [`/examples`](/examples/README.md) are good for a general grasp
298+
- with [`/examples/mach_template`](/examples/mach_template) being ready for copy-paste
257299
- [`/docs/manual.md`](/docs/manual.md)
258300
and [`/docs/diagrams.md`](/docs/diagrams.md) go deeper into implementation details
259301
- [`/tools/cmd/am-gen`](/tools/cmd/am-gen) will bootstrap
260-
- [`/examples/mach_template`](/examples/mach_template) is copy-paste ready
261-
- [`/tools/cmd/am-dbg`](/tools/cmd/am-dbg) records every detail
262-
- [reading tests](https://github.com/search?q=repo%3Apancsta%2Fasyncmachine-go+path%3A%2F.*_test.go%2F&type=code)
302+
- [`/tools/cmd/am-dbg`](/tools/cmd/am-dbg) will record every detail
303+
- and [reading tests](https://github.com/search?q=repo%3Apancsta%2Fasyncmachine-go+path%3A%2F.*_test.go%2F&type=code)
263304
is always a good idea
264305

265306
## [Packages](/pkg)
266307

267-
This monorepo offers the following importable packages and runnable tools, especially:
308+
This monorepo offers the following importable packages, especially:
268309

269310
- 🦾 **[`/pkg/machine`](/pkg/machine/README.md) State machine, dependency free, semver compatible.**
270311
- [`/pkg/states`](/pkg/states/README.md) Reusable state schemas, handlers, and piping.
271312
- [`/pkg/helpers`](/pkg/helpers/README.md) Useful functions when working with async state machines.
272313
- [`/pkg/telemetry`](/pkg/telemetry/README.md) Telemetry exporters for dbg, metrics, traces, and logs.
273314

274-
Remaining packages:
315+
Other packages:
275316

276317
- [`/pkg/graph`](/pkg/graph) Multigraph of interconnected state machines.
277318
- [`/pkg/history`](/pkg/history/README.md) History tracking and traversal.
278319
- [`/pkg/integrations`](/pkg/integrations/README.md) NATS and other JSON integrations.
279320
- [`/pkg/node`](/pkg/node/README.md) Distributed worker pools with supervisors.
280321
- [`/pkg/rpc`](/pkg/rpc/README.md) Remote state machines, with the same API as local ones.
281322
- [`/pkg/pubsub`](/pkg/pubsub/README.md) Decentralized PubSub based on libp2p gossipsub.
323+
324+
## [Devtools](/tools)
325+
282326
- [`/tools/cmd/am-dbg`](/tools/cmd/am-dbg/README.md) Multi-client TUI debugger.
283327
- [`/tools/cmd/am-gen`](/tools/cmd/am-gen/README.md) Generates schema files and Grafana dashboards.
284328
- [`/tools/cmd/am-vis`](https://github.com/pancsta/asyncmachine-go/pull/216) Generates diagrams of interconnected state machines.
@@ -305,6 +349,14 @@ Remaining packages:
305349
- [Changing State](/docs/manual.md#changing-state)
306350
- [Advanced Topics](/docs/manual.md#advanced-topics)
307351
- [Cheatsheet](/docs/manual.md#cheatsheet)
352+
353+
## Goals
354+
355+
- scale up, not down
356+
- defaults work by default
357+
- everything can be traced and debugged
358+
- automation is evolution
359+
- state != data
308360

309361
## Community
310362

docs/env-configs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ AM_PUBSUB_DBG=1
164164
# defaults to ""
165165
AM_REPL_ADDR=1
166166

167-
# REPL address file dir path (`addrDir/mach-id.addr`). Optional.
167+
# REPL address file dir path (for `$AM_REPL_DIR/mach-id.addr`). Optional.
168168
# defaults to ""
169-
AM_REPL_ADDR_DIR=tmp
169+
AM_REPL_DIR=tmp
170170
```

examples/tree_state_source/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type FlightsStatesDef struct {
3838

3939
// ...
4040

41+
// inherit from BasicStatesDef
42+
*ssam.BasicStatesDef
4143
// inherit from rpc/WorkerStatesDef
4244
*ssrpc.WorkerStatesDef
4345
}

pkg/machine/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (h *Handlers) ProcessingFileState(e *am.Event) {
173173
// no blocking
174174
// lock-free critical section
175175
mach := e.Machine
176-
// clock-based context
176+
// clock-based expiration context
177177
stateCtx := mach.NewStateCtx("ProcessingFile")
178178
// unblock
179179
go func() {
@@ -209,6 +209,9 @@ func (h *Handlers) ProcessingFileState(e *am.Event) {
209209
// wait for EventConnected to be activated with an arg ID=123
210210
<-mach.WhenArgs("EventConnected", am.A{"ID": 123}, nil)
211211

212+
// wait for Foo to have a tick >= 6
213+
<-mach.WhenTime1("Foo", 6, nil)
214+
212215
// wait for Foo to have a tick >= 6 and Bar tick >= 10
213216
<-mach.WhenTime(am.S{"Foo", "Bar"}, am.Time{6, 10}, nil)
214217

@@ -343,6 +346,7 @@ The most common API methods are listed below. There's more for [local state mach
343346
but all of these are also implemented in the [transparent RPC layer](/pkg/rpc/README.md).
344347

345348
```go
349+
// TODO update
346350
// A (arguments) is a map of named arguments for a Mutation.
347351
type A map[string]any
348352
// S (state names) is a string list of state names.
@@ -506,6 +510,7 @@ Release Candidate, semantically versioned, not optimized yet.
506510
- [SQL relations](https://en.wikipedia.org/wiki/SQL)
507511
- [Paxos negotiation](https://en.wikipedia.org/wiki/Paxos_(computer_science))
508512
- [logical clock](https://en.wikipedia.org/wiki/Logical_clock)
513+
- [programming by contract](https://en.wikipedia.org/wiki/Design_by_contract)
509514
- [non-blocking](https://en.wikipedia.org/wiki/Non-blocking_algorithm)
510515
- [Actor Model](https://en.wikipedia.org/wiki/Actor_model)
511516
- [causal inference](https://en.wikipedia.org/wiki/Causal_inference)

pkg/states/ss_disposed.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (h *DisposedHandlers) RegisterDisposalEnter(e *am.Event) bool {
6868
fn, ok := e.Args[DisposedArgHandler].(am.HandlerDispose)
6969
ret := ok && fn != nil
7070
// avoid errs on check mutations
71-
if ret == false && !e.IsCheck {
71+
if !ret && !e.IsCheck {
7272
err := fmt.Errorf("%w: DisposedArgHandler invalid", am.ErrInvalidArgs)
7373
e.Machine().AddErr(err, nil)
7474
}

pkg/telemetry/README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ added as well.
6060
See [/docs/env-configs.md](/docs/env-configs.md) for the required environment variables.
6161

6262
```go
63-
// root machines only
64-
if mach.ParentId() == "" {
65-
// open telemetry traces
66-
err = amtele.MachBindOtelEnv(mach)
67-
if err != nil {
63+
import amtele "github.com/pancsta/asyncmachine-go/pkg/telemetry"
64+
65+
// ...
66+
67+
var mach *am.Machine
68+
69+
// open telemetry traces
70+
err = amtele.MachBindOtelEnv(mach)
71+
if err != nil {
6872
mach.AddErr(err, nil)
69-
}
7073
}
7174
```
7275

@@ -127,11 +130,14 @@ Tracers are inherited from parent machines.
127130
See [/docs/env-configs.md](/docs/env-configs.md) for the required environment variables.
128131

129132
```go
130-
// root machines only
131-
if mach.ParentId() == "" {
132-
// export metrics to prometheus
133-
metrics := amprom.MachMetricsEnv(mach)
134-
}
133+
import amtele "github.com/pancsta/asyncmachine-go/pkg/telemetry"
134+
135+
// ...
136+
137+
var mach *am.Machine
138+
139+
// export metrics to prometheus
140+
metrics := amprom.MachMetricsEnv(mach)
135141
```
136142

137143
### Manual Prometheus Setup
@@ -142,6 +148,7 @@ import (
142148
am "github.com/pancsta/asyncmachine-go/pkg/machine"
143149
amprom "github.com/pancsta/asyncmachine-go/pkg/telemetry/prometheus"
144150
"github.com/prometheus/client_golang/prometheus/push"
151+
)
145152

146153
// ...
147154

@@ -166,13 +173,13 @@ Loki is the easiest way to persist distributed logs from asyncmachine. You'll ne
166173
See [/docs/env-configs.md](/docs/env-configs.md) for the required environment variables.
167174

168175
```go
169-
import (
170-
amtele "github.com/pancsta/asyncmachine-go/pkg/telemetry"
171-
)
176+
import amtele "github.com/pancsta/asyncmachine-go/pkg/telemetry"
172177

173178
// ...
174179

175180
var mach *am.Machine
181+
182+
// export logs to Loki logger
176183
amtele.BindLokiEnv(mach)
177184
```
178185

0 commit comments

Comments
 (0)