pomerium/pkg/fanout/publish.go
2023-12-11 17:31:39 -05:00

19 lines
428 B
Go

package fanout
import "context"
// Publish publishes a message to all currently registered subscribers
// if the fanout is closed, ErrStopped is returned
func (f *FanOut[T]) Publish(ctx context.Context, msg T) error {
ctx, cancel := context.WithTimeout(ctx, f.cfg.publishTimeout)
defer cancel()
select {
case <-ctx.Done():
return ctx.Err()
case <-f.done:
return ErrStopped
case f.messages <- msg:
return nil
}
}