Started working on the event bus
This commit is contained in:
parent
fdd2ecc7fc
commit
e2f159e980
9 changed files with 233 additions and 61 deletions
31
models/events.go
Normal file
31
models/events.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package models
|
||||
|
||||
import "container/list"
|
||||
|
||||
type EventType int
|
||||
|
||||
const (
|
||||
// EventTypeSubscribe event type for the bus indicating a new subscription.
|
||||
// Data is a (chan Sub) to send the new subscription
|
||||
EventTypeSubscribe EventType = iota
|
||||
|
||||
// EventTypeUnsubscribe event type for the bus indicating to remove a subscription.
|
||||
// Data is the Sub type
|
||||
EventTypeUnsubscribe
|
||||
|
||||
// EventSiteBuildingStart indicates that the site has started being built. Data = site
|
||||
EventSiteBuildingStart = 2
|
||||
|
||||
// EventSiteBuildingDone indicates that the site has finish building. Data = site
|
||||
EventSiteBuildingDone = 3
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Type EventType
|
||||
Data any
|
||||
}
|
||||
|
||||
type Sub struct {
|
||||
C chan Event
|
||||
Elem *list.Element
|
||||
}
|
||||
|
|
@ -5,14 +5,3 @@ import "context"
|
|||
type Job struct {
|
||||
Do func(ctx context.Context) error
|
||||
}
|
||||
|
||||
func Jobs(jobs ...Job) Job {
|
||||
return Job{Do: func(ctx context.Context) error {
|
||||
for _, job := range jobs {
|
||||
if err := job.Do(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue