mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-02 11:56:02 +02:00
19 lines
428 B
Go
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
|
|
}
|
|
}
|