mirror of https://github.com/panjf2000/ants.git
chore: rename the method 'when' of worker to 'lastUsedTime'
This commit is contained in:
parent
e425c7b917
commit
55e222d20f
|
@ -76,7 +76,7 @@ func (w *goWorker) finish() {
|
||||||
w.task <- nil
|
w.task <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *goWorker) when() time.Time {
|
func (w *goWorker) lastUsedTime() time.Time {
|
||||||
return w.lastUsed
|
return w.lastUsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (w *goWorkerWithFunc) finish() {
|
||||||
w.args <- nil
|
w.args <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *goWorkerWithFunc) when() time.Time {
|
func (w *goWorkerWithFunc) lastUsedTime() time.Time {
|
||||||
return w.lastUsed
|
return w.lastUsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (wq *loopQueue) binarySearch(expiryTime time.Time) int {
|
||||||
nlen = len(wq.items)
|
nlen = len(wq.items)
|
||||||
|
|
||||||
// if no need to remove work, return -1
|
// if no need to remove work, return -1
|
||||||
if wq.isEmpty() || expiryTime.Before(wq.items[wq.head].when()) {
|
if wq.isEmpty() || expiryTime.Before(wq.items[wq.head].lastUsedTime()) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ func (wq *loopQueue) binarySearch(expiryTime time.Time) int {
|
||||||
mid = l + ((r - l) >> 1)
|
mid = l + ((r - l) >> 1)
|
||||||
// calculate true mid position from mapped mid position
|
// calculate true mid position from mapped mid position
|
||||||
tmid = (mid + basel + nlen) % nlen
|
tmid = (mid + basel + nlen) % nlen
|
||||||
if expiryTime.Before(wq.items[tmid].when()) {
|
if expiryTime.Before(wq.items[tmid].lastUsedTime()) {
|
||||||
r = mid - 1
|
r = mid - 1
|
||||||
} else {
|
} else {
|
||||||
l = mid + 1
|
l = mid + 1
|
||||||
|
|
|
@ -118,7 +118,7 @@ func TestRotatedArraySearch(t *testing.T) {
|
||||||
// [expiry4, time, time, time, time, expiry5, time, time, time, time/head/tail]
|
// [expiry4, time, time, time, time, expiry5, time, time, time, time/head/tail]
|
||||||
assert.EqualValues(t, -1, q.binarySearch(expiry2), "index should be -1")
|
assert.EqualValues(t, -1, q.binarySearch(expiry2), "index should be -1")
|
||||||
|
|
||||||
assert.EqualValues(t, 9, q.binarySearch(q.items[9].when()), "index should be 9")
|
assert.EqualValues(t, 9, q.binarySearch(q.items[9].lastUsedTime()), "index should be 9")
|
||||||
assert.EqualValues(t, 8, q.binarySearch(time.Now()), "index should be 8")
|
assert.EqualValues(t, 8, q.binarySearch(time.Now()), "index should be 8")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ var (
|
||||||
type worker interface {
|
type worker interface {
|
||||||
run()
|
run()
|
||||||
finish()
|
finish()
|
||||||
when() time.Time
|
lastUsedTime() time.Time
|
||||||
inputFunc(func())
|
inputFunc(func())
|
||||||
inputParam(interface{})
|
inputParam(interface{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (wq *workerStack) binarySearch(l, r int, expiryTime time.Time) int {
|
||||||
var mid int
|
var mid int
|
||||||
for l <= r {
|
for l <= r {
|
||||||
mid = (l + r) / 2
|
mid = (l + r) / 2
|
||||||
if expiryTime.Before(wq.items[mid].when()) {
|
if expiryTime.Before(wq.items[mid].lastUsedTime()) {
|
||||||
r = mid - 1
|
r = mid - 1
|
||||||
} else {
|
} else {
|
||||||
l = mid + 1
|
l = mid + 1
|
||||||
|
|
Loading…
Reference in New Issue