diff options
author | Jhon Honce <jhonce@redhat.com> | 2022-04-04 13:04:40 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2022-05-03 13:49:01 -0700 |
commit | 8da5f3f733273245dd4e86324ca88bf8e4ede37a (patch) | |
tree | 2c87e85d53cf01763fec61464e5a208b18de83ae /libpod/events/memory.go | |
parent | 1e0c50df38ff955011f7ebb83a0268f3f1cd2841 (diff) | |
download | podman-8da5f3f733273245dd4e86324ca88bf8e4ede37a.tar.gz podman-8da5f3f733273245dd4e86324ca88bf8e4ede37a.tar.bz2 podman-8da5f3f733273245dd4e86324ca88bf8e4ede37a.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.go | 49 |
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), + } +} |