MCPcopy
hub / github.com/panjf2000/ants / refresh

Method refresh

worker_stack.go:64–83  ·  view source on GitHub ↗
(duration time.Duration)

Source from the content-addressed store, hash-verified

62}
63
64func (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
85func (ws *workerStack) binarySearch(l, r int, expiryTime int64) int {
86 for l <= r {

Callers

nothing calls this directly

Calls 2

lenMethod · 0.95
binarySearchMethod · 0.95

Tested by

no test coverage detected