machine/message.go

31 lines
485 B
Go
Raw Normal View History

2024-04-04 17:33:22 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
2024-04-04 20:08:50 +00:00
2024-04-04 17:33:22 +00:00
package machine
import (
2024-04-04 20:08:50 +00:00
"fmt"
2024-04-04 17:33:22 +00:00
)
const (
2024-04-04 20:08:50 +00:00
ENTERSTATEEVENT = iota
EXITSTATEEVENT
2024-04-04 17:33:22 +00:00
)
type Eventtype int
type EventMessage struct {
2024-04-04 20:08:50 +00:00
on Eventtype
source State
dest State
2024-04-04 17:33:22 +00:00
}
type EventChannel chan EventMessage
func (e *EventChannel) Notify(m *EventMessage) {
2024-04-04 20:08:50 +00:00
*e <- *m
2024-04-04 17:33:22 +00:00
}
func (m EventMessage) String() string {
2024-04-04 20:08:50 +00:00
return fmt.Sprintf("{on: %d, source: %s, dest: %s}", m.on, m.source, m.dest)
2024-04-04 17:33:22 +00:00
}