mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 10:26:29 +02:00
This also replaces instances where we manually write "return ctx.Err()" with "return context.Cause(ctx)" which is functionally identical, but will also correctly propagate cause errors if present.
19 lines
437 B
Go
19 lines
437 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 context.Cause(ctx)
|
|
case <-f.done:
|
|
return ErrStopped
|
|
case f.messages <- msg:
|
|
return nil
|
|
}
|
|
}
|