From 48a8f7775bf4c626a61c9db10208795fbea8f305 Mon Sep 17 00:00:00 2001 From: Planxnx Date: Wed, 25 Oct 2023 19:30:22 +0700 Subject: [PATCH] docs: add queue go-reference example usage --- queue/doc.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 queue/doc.go diff --git a/queue/doc.go b/queue/doc.go new file mode 100644 index 0000000..8120f0b --- /dev/null +++ b/queue/doc.go @@ -0,0 +1,43 @@ +/* +# Example + +Basic usage: + + q := New[string]() + q.Enqueue("Foo") + + item, ok := q.Dequeue() + if !ok { + panic("item should be dequeued") + } + fmt.Println(item) // Output: Foo + +Concurrency usage: + + q := New[string]() + + go func() { + for { + item, ok := q.Dequeue() + if !ok { + break + } + fmt.Println(item) + } + }() + + data := []string{"Foo", "Bar", "Baz"} + for _, item := range data { + q.Enqueue(item) + } + + q.Close() // close queue to stop goroutine + +Queue is unlimited capacity, so you can enqueue as many as you want without blocking or dequeue required: + + q := New[string]() + for i := 0; i < 1000000; i++ { + q.Enqueue("Foo") + } +*/ +package queue