package main
import (
"context"
"time"
"github.com/joho/godotenv"
amhelp "github.com/pancsta/asyncmachine-go/pkg/helpers"
am "github.com/pancsta/asyncmachine-go/pkg/machine"
amxhelp "github.com/pancsta/asyncmachine-go/pkg/x/helpers"
)
func init() {
_ = godotenv .Load ()
amhelp .EnableDebugging (false )
amhelp .SetEnvLogLevel (am .LogChanges )
}
func main() {
ctx := context .Background ()
states := am .Schema {
"Task" : {Require : am .S {"Start" }},
"TaskDone" : {},
"Start" : {},
"Ready" : {
Auto : true ,
Require : am .S {"TaskDone" },
},
"Healthcheck" : {Multi : true },
}
names := am .S {"Start" , "Task" , "TaskDone" , "Ready" , "Healthcheck" , am .StateException }
mach , err := am .NewCommon (ctx , "fan" , states , names , &am .ExceptionHandler {}, nil , &am .Opts {
LogLevel : am .LogOps ,
})
if err != nil {
panic (err )
}
amhelp .MachDebugEnv (mach )
fn := func (num int , state , stateDone string ) {
ctx := mach .NewStateCtx (state )
go func () {
if ctx .Err () != nil {
return
}
amhelp .Wait (ctx , time .Second )
if ctx .Err () != nil {
return
}
mach .Add1 (stateDone , nil )
}()
}
_, err = amxhelp .FanOutIn (mach , "Task" , 15 , 3 , fn )
if err != nil {
panic (err )
}
mach .Add (am .S {"Start" , "Task" }, nil )
<-mach .When1 ("Ready" , nil )
println ("done" )
time .Sleep (time .Second )
}
The pages are generated with Golds v0.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 .