MCPcopy Index your code
hub / github.com/coder/coder / Push

Method Push

cli/cliutil/queue.go:48–69  ·  view source on GitHub ↗

Push adds an item to the queue. If closed, returns an error.

(x T)

Source from the content-addressed store, hash-verified

46
47// Push adds an item to the queue. If closed, returns an error.
48func (q *Queue[T]) Push(x T) error {
49 q.mu.Lock()
50 defer q.mu.Unlock()
51 if q.closed {
52 return xerrors.New("queue has been closed")
53 }
54 // Potentially mutate or skip the push using the predicate.
55 if q.pred != nil {
56 var ok bool
57 x, ok = q.pred(x)
58 if !ok {
59 return nil
60 }
61 }
62 // Remove the first item from the queue if it has gotten too big.
63 if len(q.items) >= q.size {
64 q.items = q.items[1:]
65 }
66 q.items = append(q.items, x)
67 q.cond.Broadcast()
68 return nil
69}
70
71// Pop removes and returns the first item from the queue, waiting until there is
72// something to pop if necessary. If closed, returns false.

Callers 3

startWatcherMethod · 0.45
startServerMethod · 0.45
TestQueueFunction · 0.45

Calls 3

NewMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestQueueFunction · 0.36