Earlier quoted context omitted.
This would be hilarious if it was satire
[flagged]
Show HN: State Trooper – Tiny, no frills state machine for Go
11–20 of 63 posts
Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#12Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#13Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#14Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#15Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#16May I suggest for a logo: A directed graph in the form of a sheriff's star badge
Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#17Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#18Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#19A state machine (specifically a FSM) class is something I end up having to reinvent in every new language I've adopted. Such a useful pattern whose need comes up repeatedly. Especially in games/sims or in anything with a GUI. Since I've been making both for decades I have a lot of homegrown FSM classes sitting around. :-p
The runtime is multithreaded and parallel.
The idea is to execute the following state machine:
thread(s) = fact(variable) | send(message) | receive(message2);
thread(r) = fact(variable) | receive(message) | send(message2);
This program waits until thread(s) is true in another thread until thread(r) is true, everything left of the equals symbol needs to be true before it passes to the next group of facts after the = symbol. Then it waits for "fact(variable)" to be fired, then when all those atoms are true, the state transitions past the pipe symbol and does a send(message) while the other thread does a receive(message) and then the process is repeated in the opposite direction. I've not shown it here, but you can wait for multiple facts to be true too.Here's a state machine for an (echo) server that is intended to be mapped to epoll or libiouring:
accept | { submit_recv! | recv | submit_send } { submit_send! | send | submit_recv }
The curly brackets means parallel state machines that run independently, like a fork.Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#20enums with associated values (like in swift) really are the thing i miss the most in go.
I really don't get how one can suggest the iota const dance with a straight face as an alternative.