From 56830d492103253ef9b9bd6414d0c5a23c35b21a Mon Sep 17 00:00:00 2001 From: EdwardDowling Date: Sun, 12 Apr 2020 15:43:24 +0100 Subject: [PATCH] Add Items() to fork of sheerun/queue --- go.mod | 3 +++ queue.go | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..56c93cb --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/EdwardDowling/queue + +go 1.14 diff --git a/queue.go b/queue.go index 46822f7..5fe4633 100644 --- a/queue.go +++ b/queue.go @@ -221,3 +221,14 @@ func (q *Queue) Remove(elem interface{}) bool { delete(q.items, id) return true } + +// Returns a slice of the items in the queue +func (q *Queue) Items() []interface{} { + q.mutex.Lock() + defer q.mutex.Unlock() + ret := []interface{}{} + for _, v := range q.items { + ret = append(ret, v) + } + return ret +}