MCPcopy Create free account
hub / github.com/beeker1121/goque / Example_queue

Function Example_queue

example_queue_test.go:10–51  ·  view source on GitHub ↗

ExampleQueue demonstrates the implementation of a Goque queue.

()

Source from the content-addressed store, hash-verified

8
9// ExampleQueue demonstrates the implementation of a Goque queue.
10func Example_queue() {
11 // Open/create a queue.
12 q, err := goque.OpenQueue("data_dir")
13 if err != nil {
14 fmt.Println(err)
15 return
16 }
17 defer q.Close()
18
19 // Enqueue an item.
20 item, err := q.Enqueue([]byte("item value"))
21 if err != nil {
22 fmt.Println(err)
23 return
24 }
25
26 fmt.Println(item.ID) // 1
27 fmt.Println(item.Key) // [0 0 0 0 0 0 0 1]
28 fmt.Println(item.Value) // [105 116 101 109 32 118 97 108 117 101]
29 fmt.Println(item.ToString()) // item value
30
31 // Change the item value in the queue.
32 item, err = q.Update(item.ID, []byte("new item value"))
33 if err != nil {
34 fmt.Println(err)
35 return
36 }
37
38 fmt.Println(item.ToString()) // new item value
39
40 // Dequeue the next item.
41 deqItem, err := q.Dequeue()
42 if err != nil {
43 fmt.Println(err)
44 return
45 }
46
47 fmt.Println(deqItem.ToString()) // new item value
48
49 // Delete the queue and its database.
50 q.Drop()
51}

Callers

nothing calls this directly

Calls 7

OpenQueueFunction · 0.92
CloseMethod · 0.45
EnqueueMethod · 0.45
ToStringMethod · 0.45
UpdateMethod · 0.45
DequeueMethod · 0.45
DropMethod · 0.45

Tested by

no test coverage detected