events.go 482 B

12345678910111213141516171819202122232425262728
  1. package pubsub
  2. import "context"
  3. const (
  4. CreatedEvent EventType = "created"
  5. UpdatedEvent EventType = "updated"
  6. DeletedEvent EventType = "deleted"
  7. )
  8. type Suscriber[T any] interface {
  9. Subscribe(context.Context) <-chan Event[T]
  10. }
  11. type (
  12. // EventType identifies the type of event
  13. EventType string
  14. // Event represents an event in the lifecycle of a resource
  15. Event[T any] struct {
  16. Type EventType
  17. Payload T
  18. }
  19. Publisher[T any] interface {
  20. Publish(EventType, T)
  21. }
  22. )