Skip to content

Commit

Permalink
docs: add queue go-reference example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Planxnx committed Oct 25, 2023
1 parent 2c60e1a commit 48a8f77
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions queue/doc.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 48a8f77

Please sign in to comment.