-
Notifications
You must be signed in to change notification settings - Fork 31
/
writer.go
42 lines (34 loc) · 859 Bytes
/
writer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package events
import (
"context"
)
// Writer provides write access to a task's events
type Writer interface {
WriteEvent(context.Context, *Event) error
Close()
}
// MultiWriter allows writing an event to a list of Writers.
// Writing stops on the first error.
type MultiWriter []Writer
// WriteEvent writes an event to all the writers. Writing stops on the first error.
func (mw *MultiWriter) WriteEvent(ctx context.Context, ev *Event) error {
for _, w := range *mw {
err := w.WriteEvent(ctx, ev)
if err != nil {
return err
}
}
return nil
}
func (mw *MultiWriter) Close() {
for _, w := range *mw {
w.Close()
}
}
// Noop provides an event writer that does nothing.
type Noop struct{}
// WriteEvent does nothing and returns nil.
func (n Noop) WriteEvent(ctx context.Context, ev *Event) error {
return nil
}
func (n Noop) Close() {}