opencode/internal/pubsub/events.go

29 lines
482 B
Go
Raw Normal View History

2025-03-22 01:20:28 +08:00
package pubsub
2025-03-24 02:19:08 +08:00
import "context"
2025-03-22 01:20:28 +08:00
const (
CreatedEvent EventType = "created"
UpdatedEvent EventType = "updated"
DeletedEvent EventType = "deleted"
)
2025-03-24 02:19:08 +08:00
type Suscriber[T any] interface {
Subscribe(context.Context) <-chan Event[T]
}
2025-03-22 01:20:28 +08:00
type (
// EventType identifies the type of event
EventType string
// Event represents an event in the lifecycle of a resource
Event[T any] struct {
Type EventType
Payload T
}
Publisher[T any] interface {
Publish(EventType, T)
}
)