package main
import (
am "github.com/pancsta/asyncmachine-go/pkg/machine"
)
const log = am .LogOps
func init() {
}
func main() {
FooBar ()
FileProcessed ()
DryWaterWet ()
RemoveByAdd ()
AddOptionalRemoveMandatory ()
Mutex ()
Quiz ()
}
func FooBar () {
mach := newMach ("FooBar" , am .Schema {
"Foo" : {Require : am .S {"Bar" }},
"Bar" : {},
})
mach .Add1 ("Foo" , nil )
}
func FileProcessed () {
mach := newMach ("FileProcessed" , am .Schema {
"ProcessingFile" : {
Remove : am .S {"FileProcessed" },
},
"FileProcessed" : {
Remove : am .S {"ProcessingFile" },
},
"InProgress" : {
Auto : true ,
Require : am .S {"ProcessingFile" },
},
})
lastTx := am .NewLastTxTracer ()
err := mach .BindTracer (lastTx )
if err != nil {
panic (err )
}
mach .Add1 ("ProcessingFile" , nil )
mach .Add1 ("FileProcessed" , nil )
println (lastTx )
}
func DryWaterWet () {
mach := newMach ("DryWaterWet" , am .Schema {
"Wet" : {
Require : am .S {"Water" },
},
"Dry" : {
Remove : am .S {"Water" },
},
"Water" : {
Add : am .S {"Wet" },
Remove : am .S {"Dry" },
},
})
mach .Add1 ("Dry" , nil )
mach .Add1 ("Water" , nil )
mach .Add1 ("Dry" , nil )
}
func RemoveByAdd () {
mach := newMach ("RemoveByNonCalled" , am .Schema {
"A" : {Add : am .S {"B" }},
"B" : {Remove : am .S {"C" }},
"C" : {},
})
mach .Add1 ("C" , nil )
mach .Add1 ("A" , nil )
}
func AddOptionalRemoveMandatory () {
mach := newMach ("AddIsOptional" , am .Schema {
"A" : {Add : am .S {"B" }},
"B" : {},
"C" : {Remove : am .S {"B" }},
})
mach .Add (am .S {"A" , "C" }, nil )
}
func Mutex () {
mach := newMach ("Mutex" , am .Schema {
"A" : {Remove : am .S {"A" , "B" , "C" }},
"B" : {Remove : am .S {"A" , "B" , "C" }},
"C" : {Remove : am .S {"A" , "B" , "C" }},
})
mach .Add1 ("A" , nil )
mach .Add1 ("B" , nil )
mach .Add1 ("C" , nil )
}
func Quiz () {
mach := newMach ("Quiz" , am .Schema {
"A" : {Add : am .S {"B" }},
"B" : {
Require : am .S {"D" },
Add : am .S {"C" },
},
"C" : {},
"D" : {Remove : am .S {"C" }},
"E" : {Add : am .S {"D" }},
})
mach .Add (am .S {"A" , "E" }, nil )
}
func newMach(id string , machSchema am .Schema ) *am .Machine {
mach := am .New (nil , machSchema , &am .Opts {
Id : id ,
DontLogId : true ,
Tracers : []am .Tracer {&Tracer {}},
LogLevel : log ,
})
println ("\n" )
println ("-----" )
println ("mach: " + mach .Id ())
println ("-----" )
return mach
}
type Tracer struct {
*am .NoOpTracer
}
func (t *Tracer ) TransitionEnd (tx *am .Transition ) {
}
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 .