(duration time.Duration)
| 62 | } |
| 63 | |
| 64 | func (ws *workerStack) refresh(duration time.Duration) []worker { |
| 65 | n := ws.len() |
| 66 | if n == 0 { |
| 67 | return nil |
| 68 | } |
| 69 | |
| 70 | expiryTime := time.Now().Add(-duration).UnixNano() |
| 71 | index := ws.binarySearch(0, n-1, expiryTime) |
| 72 | |
| 73 | ws.expiry = ws.expiry[:0] |
| 74 | if index != -1 { |
| 75 | ws.expiry = append(ws.expiry, ws.items[:index+1]...) |
| 76 | m := copy(ws.items, ws.items[index+1:]) |
| 77 | for i := m; i < n; i++ { |
| 78 | ws.items[i] = nil |
| 79 | } |
| 80 | ws.items = ws.items[:m] |
| 81 | } |
| 82 | return ws.expiry |
| 83 | } |
| 84 | |
| 85 | func (ws *workerStack) binarySearch(l, r int, expiryTime int64) int { |
| 86 | for l <= r { |
nothing calls this directly
no test coverage detected