diff --git a/event.go b/event.go index 5e8bc75..cae32af 100644 --- a/event.go +++ b/event.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "io" "log" "os" "runtime" @@ -15,6 +16,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + "go.uber.org/multierr" "golang.org/x/sync/semaphore" "github.com/prometheus/client_golang/prometheus" @@ -57,6 +59,7 @@ type Metrics interface { // Event interface type Event interface { + io.Closer // Publish send data to all subscribers Publish(context.Context, Data) // Subscribe receive data sent by Publish @@ -74,6 +77,9 @@ type discardEvent struct{} func (discardEvent) Name() string { return "" } func (discardEvent) Subscribe(_ context.Context, _ Handler) {} func (discardEvent) Publish(_ context.Context, _ Data) {} +func (discardEvent) Close() error { + return nil +} // eventImpl event implementation type eventImpl struct { @@ -363,6 +369,17 @@ func (e Events) Publish(ctx context.Context, data Data) { } } +func (e Events) Close() error { + var combinedErr error + for _, event := range e { + err := event.Close() + if err != nil { + combinedErr = multierr.Append(combinedErr, err) + } + } + return combinedErr +} + // New create new instance of event // and registers with given registry func New(name string, opts ...Option) Event {