summaryrefslogtreecommitdiff
path: root/libpod/events/memory.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/events/memory.go')
-rw-r--r--libpod/events/memory.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/libpod/events/memory.go b/libpod/events/memory.go
new file mode 100644
index 000000000..b3e03d86b
--- /dev/null
+++ b/libpod/events/memory.go
@@ -0,0 +1,49 @@
+package events
+
+import (
+ "context"
+)
+
+// EventMemory is the structure for event writing to a channel. It contains the eventer
+// options and the event itself. Methods for reading and writing are also defined from it.
+type EventMemory struct {
+ options EventerOptions
+ elements chan *Event
+}
+
+// Write event to memory queue
+func (e EventMemory) Write(event Event) (err error) {
+ e.elements <- &event
+ return
+}
+
+// Read event(s) from memory queue
+func (e EventMemory) Read(ctx context.Context, options ReadOptions) (err error) {
+ select {
+ case <-ctx.Done():
+ return
+ default:
+ }
+
+ select {
+ case event := <-e.elements:
+ options.EventChannel <- event
+ default:
+ }
+ return nil
+}
+
+// String returns eventer type
+func (e EventMemory) String() string {
+ return e.options.EventerType
+}
+
+// NewMemoryEventer returns configured MemoryEventer
+func NewMemoryEventer() Eventer {
+ return EventMemory{
+ options: EventerOptions{
+ EventerType: Memory.String(),
+ },
+ elements: make(chan *Event, 100),
+ }
+}