package mainimport (amhelpam)func init() {// load .env _ = godotenv.Load()// am-dbg is required for debugging, go run it // go run github.com/pancsta/asyncmachine-go/tools/cmd/am-dbg@latest // amhelp.EnableDebugging(false) // amhelp.SetEnvLogLevel(am.LogOps)}func main() { := context.Background()// init state machines := am.New(, am.Schema{"Foo": {},"Bar": {},"Healthcheck": {Multi: true}, }, &am.Opts{LogLevel: am.LogOps, Id: "source"})amhelp.MachDebugEnv() := sync.WaitGroup{} .Add(1)gofunc() {go .Done()// wait until FileDownloaded becomes active <-.When1("Foo", nil)fmt.Println("1 - Foo activated") }() .Add(1)gofunc() {go .Done()// wait until FileDownloaded becomes inactive <-.WhenNot1("Bar", nil)fmt.Println("2 - Bar deactivated") }() .Add(1)gofunc() {go .Done()// wait for EventConnected to be activated with an arg ID=123 <-.WhenArgs("Bar", am.A{"ID": 123}, nil)fmt.Println("3 - Bar activated with ID=123") }() .Add(1)gofunc() {go .Done()// wait for Foo to have a tick >= 1 and Bar tick >= 3 <-.WhenTime(am.S{"Foo", "Bar"}, am.Time{1, 3}, nil)fmt.Println("4 - Foo tick >= 1 and Bar tick >= 3") }() .Add(1)gofunc() {go .Done()// wait for DownloadingFile to have a tick increased by 2 since now <-.WhenTicks("Foo", 2, nil)fmt.Println("5 - Foo tick increased by 2 since now") }() .Add(1)gofunc() {go .Done()// wait for an error <-.WhenErr()fmt.Println("6 - Error") }() .Wait() .Add1("Foo", nil) .Add1("Bar", nil) .Remove1("Bar", nil) .Remove1("Foo", nil) .Add1("Foo", nil) .Add1("Bar", am.A{"ID": 123}) .AddErr(errors.New("err"), nil)// waittime.Sleep(time.Second)}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.