summaryrefslogtreecommitdiff
path: root/libpod/events/memory.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2022-04-04 13:04:40 -0700
committeropenshift-cherrypick-robot <>2022-05-04 13:42:38 +0000
commita21e112364f93a1a7d342584a239b289a8ee9f0a (patch)
treeb6c3632932fc703a82a55fc50727f24f0fc323d2 /libpod/events/memory.go
parent3210a3f4257d19744abd4ae2302018b16edb2507 (diff)
downloadpodman-a21e112364f93a1a7d342584a239b289a8ee9f0a.tar.gz
podman-a21e112364f93a1a7d342584a239b289a8ee9f0a.tar.bz2
podman-a21e112364f93a1a7d342584a239b289a8ee9f0a.zip
Add podman machine events
Signed-off-by: Jhon Honce <jhonce@redhat.com>
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),
+ }
+}