go-scopes/lib/core/core.go

34 lines
506 B
Go

package core
import (
"fmt"
"git.sr.ht/~cco/go-scopes/lib"
)
func Start(ctx lib.Context) {
Listen(ctx)
}
func Listen(ctx lib.Context) {
step := ctx.Config().Step()
for step(ctx) {
}
}
func Step(ctx lib.Context) (loop bool) {
loop = true
//defer ctx.LogCatch("Step")
select {
case msg := <-ctx.Mailbox():
loop = ctx.HandleMsg(msg)
case <-ctx.Done():
loop = false
}
return
}
func HandleMessage(ctx lib.Context, msg lib.Message) bool {
fmt.Println("HandleMessage", msg)
return true
}