Finds next queue for the querier. To support fair scheduling between users, client is expected to pass last user index returned by this function as argument. Is there was no previous last user index, use -1.
(lastUserIndex int)
| 102 | // to pass last user index returned by this function as argument. Is there was no previous |
| 103 | // last user index, use -1. |
| 104 | func (q *queues) getNextQueueForQuerier(lastUserIndex int) (chan Request, string, int) { |
| 105 | uid := lastUserIndex |
| 106 | |
| 107 | for iters := 0; iters < len(q.users); iters++ { |
| 108 | uid = uid + 1 |
| 109 | |
| 110 | // Don't use "mod len(q.users)", as that could skip users at the beginning of the list |
| 111 | // for example when q.users has shrunk since last call. |
| 112 | if uid >= len(q.users) { |
| 113 | uid = 0 |
| 114 | } |
| 115 | |
| 116 | u := q.users[uid] |
| 117 | if u == "" { |
| 118 | continue |
| 119 | } |
| 120 | |
| 121 | q := q.userQueues[u] |
| 122 | |
| 123 | if len(q.ch) == 0 { |
| 124 | continue |
| 125 | } |
| 126 | |
| 127 | return q.ch, u, uid |
| 128 | } |
| 129 | return nil, "", uid |
| 130 | } |
no outgoing calls
no test coverage detected