Skip to content

Commit

Permalink
feat: release v0.10 reminders (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
pancsta authored Jan 16, 2025
1 parent 155de0b commit 60dcbbe
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 151 deletions.
14 changes: 14 additions & 0 deletions BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

Only `pkg/machine` and `pkg/states` adhere to semver. Semver of other packages is not guaranteed at the moment.

## v0.10

- `FooBar` handlers execute later and more often
- `FooAny`, `AnyFoo` handlers has been removed
- `AnyAny` is now `AnyEnter`

## v0.9

- `Event.Machine` is now `Event.Machine()`
- `Machine.RegisterDisposalHandler(func())` is now `HandleDispose(func(id, ctx))`
- `Step.FromState` is now `Step.GetFromState()`
- `Step.ToState` is now `Step.GetToState()`
- `Step.Data` is now `Step.RelType`

## v0.8

- `Machine.ID` is now `Id()`
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## [v0.10.0](https://github.com/pancsta/asyncmachine-go/tree/v0.10.0) (2025-01-14)

- feat\(states\): add Disposed state def [\#210](https://github.com/pancsta/asyncmachine-go/pull/210) (@pancsta)
- docs\(examples\): refac NFA example [\#209](https://github.com/pancsta/asyncmachine-go/pull/209) (@pancsta)
- feat\(machine\): allow for partial auto states via handlers [\#208](https://github.com/pancsta/asyncmachine-go/pull/208)
(@pancsta)
- fix\(node\): migrate to lock-less workers map [\#207](https://github.com/pancsta/asyncmachine-go/pull/207) (@pancsta)

## [v0.9.1](https://github.com/pancsta/asyncmachine-go/tree/v0.9.1) (2025-01-14)

- fix\(machine\): dont panic on topo sort with cycles [\#206](https://github.com/pancsta/asyncmachine-go/pull/206)
(@pancsta)
- feat\(machine\): improve state-state handlers \(eg FooBar\) [\#205](https://github.com/pancsta/asyncmachine-go/pull/205)
(@pancsta)
- fix: fix `test -race` for handler.Dispose [\#204](https://github.com/pancsta/asyncmachine-go/pull/204) (@pancsta)
- fix: fix `test -race` for handleDispose [\#203](https://github.com/pancsta/asyncmachine-go/pull/203) (@pancsta)
- ci: split go pipelines [\#202](https://github.com/pancsta/asyncmachine-go/pull/202) (@pancsta)
- fix\(dbg\): fix mouse scroll [\#201](https://github.com/pancsta/asyncmachine-go/pull/201) (@pancsta)
- feat\(dbg\): group piped states [\#200](https://github.com/pancsta/asyncmachine-go/pull/200) (@pancsta)
- fix\(dbg\): fix rain with filters [\#199](https://github.com/pancsta/asyncmachine-go/pull/199) (@pancsta)
- fix\(dbg\): improve reader links and history [\#198](https://github.com/pancsta/asyncmachine-go/pull/198) (@pancsta)
- feat\(dbg\): show tags from parent machines [\#197](https://github.com/pancsta/asyncmachine-go/pull/197) (@pancsta)

## [v0.9.0](https://github.com/pancsta/asyncmachine-go/tree/v0.9.0) (2024-12-15)

- feat: add v0.9 release [\#194](https://github.com/pancsta/asyncmachine-go/pull/194) (@pancsta)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Top layers depend on the bottom ones.
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="9" align=center><a href="pkg/machine/README.md">Machine API</a></td>
<td colspan="9" align=center>🦾 <a href="pkg/machine/README.md">Machine API</a></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
Expand Down Expand Up @@ -171,7 +171,7 @@ if err != nil {
func (h *Handlers) FooEnter(e *am.Event) bool {
return true
}
// when Foo active, can Bar activate?
// with Foo active, can Bar activate?
func (h *Handlers) FooBar(e *am.Event) bool {
return true
}
Expand Down Expand Up @@ -217,8 +217,8 @@ All examples and benchmarks can be found in [`/examples`](/examples/README.md).

## Getting Started

[`/pkg/machine`](pkg/machine/README.md) is a mandatory ready, while the code of [`/pkg/node`](pkg/node/supervisor.go) is
the most interesting one. Examples in [`/examples`](/examples/README.md) are good for a general grasp, while [`/docs/manual.md`](/docs/manual.md)
🦾 [`/pkg/machine`](pkg/machine/README.md) is the main package, while [`/pkg/node`](pkg/node) is
the high-level usage. Examples in [`/examples`](/examples/README.md) are good for a general grasp, while [`/docs/manual.md`](/docs/manual.md)
and [`/docs/diagrams.md`](/docs/diagrams.md) go deeper into implementation details. Reading tests is always a good idea.

## Packages
Expand All @@ -227,10 +227,10 @@ This monorepo offers the following importable packages and runnable tools:

- [`/pkg/helpers`](/pkg/helpers/README.md) Useful functions when working with async state machines.
- [`/pkg/history`](/pkg/history/README.md) History tracking and traversal.
- **[`/pkg/machine`](/pkg/machine/README.md) State machine, the main package. Dependency free and semver compatible.**
- 🦾 **[`/pkg/machine`](/pkg/machine/README.md) State machine, dependency free, semver compatible.**
- [`/pkg/node`](/pkg/node/README.md) Distributed worker pools with supervisors.
- [`/pkg/rpc`](/pkg/rpc/README.md) Remote state machines, with the same API as local ones.
- [`/pkg/states`](/pkg/states/README.md) Reusable state definitions and piping.
- [`/pkg/states`](/pkg/states/README.md) Reusable state definitions, handlers, and piping.
- [`/pkg/telemetry`](/pkg/telemetry/README.md) Telemetry exporters for metrics, traces, and logs.
- `/pkg/pubsub` Planned.
- [`/tools/cmd/am-dbg`](/tools/cmd/am-dbg/README.md) Multi-client TUI debugger.
Expand Down
30 changes: 28 additions & 2 deletions docs/diagrams.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Diagrams

## Machine Basics## Features
## Machine Basics

Features are explained using Mermaid flow diagrams, and headers link to relevant sections of the [manual](/docs/manual.md).

Expand Down Expand Up @@ -199,7 +199,33 @@ flowchart LR
end
```

## aRPC Architecture
## aRPC

### aRPC Client Server

```mermaid
flowchart TB
subgraph s [Server Host]
direction TB
Server[aRPC Server]
Worker[Worker Mach]
end
subgraph c [Client Host]
direction TB
Consumer[Consumer]
Client[aRPC Client]
RemoteWorker[Remote Worker Mach]
end
Client -- WorkerPayload state --> Consumer
Client --> RemoteWorker
Worker --> Server
Client -- Mutations --> Server
Server -. Clock Updates .-> Client
```

### aRPC Architecture

```mermaid
flowchart TB
Expand Down
26 changes: 1 addition & 25 deletions examples/benchmark_state_source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,7 @@ Benchmark of [`/examples/tree_state_source`](/examples/tree_state_source/README.
and [Caddy](https://caddyserver.com/) in various tree configurations. Every node is a resource limited container
(0.1cpu, 64mb). Each run starts with a restart of the load balancer and a 1s warmup.

```mermaid
flowchart BT
Root
Replicant-1 -- aRPC --> Root
Replicant-2 -- aRPC --> Root
Replicant-1-1 -- aRPC --> Replicant-1
Replicant-1-2 -- aRPC --> Replicant-1
Replicant-1-3 -- aRPC --> Replicant-1
Replicant-2-1 -- aRPC --> Replicant-2
Replicant-2-2 -- aRPC --> Replicant-2
Replicant-2-3 -- aRPC --> Replicant-2
Caddy[Caddy Load Balancer]
Caddy -- HTTP --> Replicant-1-1
Caddy -- HTTP --> Replicant-1-2
Caddy -- HTTP --> Replicant-1-3
Caddy -- HTTP --> Replicant-2-1
Caddy -- HTTP --> Replicant-2-2
Caddy -- HTTP --> Replicant-2-3
Benchmark[Benchmark go-wrt]
Benchmark -- HTTP --> Caddy
```
![diagram](https://github.com/pancsta/assets/blob/main/asyncmachine-go/diagrams/diagram_ex_2.svg)

## Results

Expand Down
15 changes: 1 addition & 14 deletions examples/tree_state_source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,7 @@
State source of flight statuses - in the real world this data-oriented problem should be modelled using composition and
handler delegation, but it's flat in this example for simplicity and research purposes.

```mermaid
flowchart BT
Root
Replicant-1 -- aRPC --> Root
Replicant-2 -- aRPC --> Root
Replicant-1-1 -- aRPC --> Replicant-1
Replicant-1-2 -- aRPC --> Replicant-1
Replicant-1-3 -- aRPC --> Replicant-1
Replicant-2-1 -- aRPC --> Replicant-2
Replicant-2-2 -- aRPC --> Replicant-2
Replicant-2-3 -- aRPC --> Replicant-2
```
![diagram](https://github.com/pancsta/assets/blob/main/asyncmachine-go/diagrams/diagram_ex_1.svg)

## States

Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <img src="https://pancsta.github.io/assets/asyncmachine-go/logo.png" height="25"/> /pkg/machine
# 🦾 /pkg/machine

[`cd /`](/README.md)

Expand Down
47 changes: 45 additions & 2 deletions pkg/machine/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,54 @@ func init() {
}

func ExampleNew() {
// TODO
ctx := context.TODO()
mach := New(ctx, Struct{
"Foo": {Require: S{"Bar"}},
"Bar": {},
}, nil)
mach.Add1("Foo", nil)
mach.Is1("Foo") // false
}

func ExampleNewCommon() {
// TODO
// define (tip: use am-gen instead)
stateStruct := Struct{
"Foo": {Require: S{"Bar"}},
"Bar": {},
}
stateNames := []string{"Foo", "Bar"}
type Handlers struct{}
// func (h *Handlers) FooState(e *Event) {
// args := e.Args
// mach := e.Machine()
// ctx := mach.NewStateCtx("Foo")
// // unblock
// go func() {
// if ctx.Err() != nil {
// return // expired
// }
// // blocking calls...
// if ctx.Err() != nil {
// return // expired
// }
// mach.Add1("Bar", nil)
// }()
// }

// init
ctx := context.TODO()
mach, err := NewCommon(ctx, "mach-id",
stateStruct, stateNames,
&Handlers{}, nil, nil)
if err != nil {
panic(err)
}
mach.SetLogLevel(LogOps)

// debug
// import amhelp "github.com/pancsta/asyncmachine-go/pkg/helpers"
// amhelp.EnableDebugging(false)
// amhelp.MachDebugEnv(mach)
}

// NewNoRels creates a new machine with no relations between states.
Expand Down
15 changes: 9 additions & 6 deletions pkg/machine/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,16 @@ func (t *Transition) emitSelfEvents() Result {
}

func (t *Transition) emitEnterEvents() Result {
for i, toState := range t.Enters {
for _, toState := range t.Enters {
args := t.Mutation.Args

// FooEnter
ret := t.emitHandler("", toState, toState+SuffixEnter, args)
if ret == Canceled {
if t.IsAuto() {
// partial auto state acceptance
t.TargetIndexes = slices.Delete(t.TargetIndexes, i, i+1)
idx := slices.Index(t.TargetStates(), toState)
t.TargetIndexes = slices.Delete(t.TargetIndexes, idx, idx+1)
} else {
return ret
}
Expand All @@ -333,13 +334,14 @@ func (t *Transition) emitEnterEvents() Result {
}

func (t *Transition) emitExitEvents() Result {
for i, fromState := range t.Exits {
for _, fromState := range t.Exits {
// FooExit
ret := t.emitHandler(fromState, "", fromState+SuffixExit, t.Mutation.Args)
if ret == Canceled {
if t.IsAuto() {
// partial auto state acceptance
t.TargetIndexes = slices.Delete(t.TargetIndexes, i, i+1)
idx := slices.Index(t.TargetStates(), fromState)
t.TargetIndexes = slices.Delete(t.TargetIndexes, idx, idx+1)
} else {
return ret
}
Expand Down Expand Up @@ -396,7 +398,7 @@ func (t *Transition) emitFinalEvents() Result {

func (t *Transition) emitStateStateEvents() Result {
for _, before := range t.StatesBefore() {
for i, after := range t.TargetStates() {
for _, after := range t.TargetStates() {
if before == after {
continue
}
Expand All @@ -415,7 +417,8 @@ func (t *Transition) emitStateStateEvents() Result {
if ret == Canceled {
if t.IsAuto() {
// partial auto state acceptance
t.TargetIndexes = slices.Delete(t.TargetIndexes, i, i+1)
idx := slices.Index(t.TargetStates(), after)
t.TargetIndexes = slices.Delete(t.TargetIndexes, idx, idx+1)
} else {
return ret
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/machine/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func captureLog(t *testing.T, m *Machine, log *string) {
mx := sync.Mutex{}
m.SetLogLevel(LogEverything)
m.SetLogger(func(i LogLevel, msg string, args ...any) {
if m.IsDisposed() {
return
}
if os.Getenv(EnvAmDebug) != "" {
t.Logf(msg+"\n", args...)
}
Expand Down
56 changes: 1 addition & 55 deletions pkg/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,61 +41,7 @@ import amnode "github.com/pancsta/asyncmachine-go/pkg/node"
- supervisor maintains the worker, eg triggers log rotation, monitors errors and restarts
- worker delivers payload to the client via ClientSendPayload

```mermaid
flowchart LR
c1-RemoteWorker -- aRPC --> w1-rpcPub
c1-RemoteSupervisor -- aRPC --> s1-rpcPub
subgraph Client 1
c1-Client[Client]
c1-RemoteWorker[RemoteWorker]
c1-RemoteSupervisor[RemoteSupervisor]
c1-Client --> c1-RemoteWorker
c1-Client --> c1-RemoteSupervisor
end
subgraph Client 2
c2-Client[Client]
c2-RemoteWorker[RemoteWorker]
c2-RemoteSupervisor[RemoteSupervisor]
c2-Client --> c2-RemoteWorker
c2-Client --> c2-RemoteSupervisor
end
subgraph Node Host
subgraph Worker Pool
w1-rpcPub --> Worker1
w1-rpcPub([Public aRPC])
w1-rpcPriv --> Worker1
w1-rpcPriv([Private aRPC])
w2-rpcPub --> Worker2
w2-rpcPub([Public aRPC])
w2-rpcPriv --> Worker2
w2-rpcPriv([Private aRPC])
w3-rpcPub --> Worker3
w3-rpcPub([Public aRPC])
w3-rpcPriv --> Worker3
w3-rpcPriv([Private aRPC])
end
s1-rpcPub([Public aRPC])
s1-rpcPub --> Supervisor1
Supervisor1 --> RemoteWorker1
Supervisor1[Supervisor]
RemoteWorker1 -- aRPC --> w1-rpcPriv
Supervisor1 -- fork --> Worker1
Supervisor1 --> RemoteWorker2
RemoteWorker2 -- aRPC --> w2-rpcPriv
Supervisor1 -- fork --> Worker2
Supervisor1 --> RemoteWorker3
RemoteWorker3 -- aRPC --> w3-rpcPriv
Supervisor1 -- fork --> Worker3
end
c2-RemoteWorker -- aRPC --> w2-rpcPub
c2-RemoteSupervisor -- aRPC --> s1-rpcPub
```
![diagram](https://github.com/pancsta/assets/blob/main/asyncmachine-go/diagrams/diagram_10.svg)

## Components

Expand Down
Loading

0 comments on commit 60dcbbe

Please sign in to comment.