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
|
||||
}
|
||||
|
||||
func (w *goWorker) when() time.Time {
|
||||
func (w *goWorker) lastUsedTime() time.Time {
|
||||
return w.lastUsed
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ func (w *goWorkerWithFunc) finish() {
|
|||
w.args <- nil
|
||||
}
|
||||
|
||||
func (w *goWorkerWithFunc) when() time.Time {
|
||||
func (w *goWorkerWithFunc) lastUsedTime() time.Time {
|
||||
return w.lastUsed
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ func (wq *loopQueue) binarySearch(expiryTime time.Time) int {
|
|||
nlen = len(wq.items)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ func (wq *loopQueue) binarySearch(expiryTime time.Time) int {
|
|||
mid = l + ((r - l) >> 1)
|
||||
// calculate true mid position from mapped mid position
|
||||
tmid = (mid + basel + nlen) % nlen
|
||||
if expiryTime.Before(wq.items[tmid].when()) {
|
||||
if expiryTime.Before(wq.items[tmid].lastUsedTime()) {
|
||||
r = mid - 1
|
||||
} else {
|
||||
l = mid + 1
|
||||
|
|
|
@ -118,7 +118,7 @@ func TestRotatedArraySearch(t *testing.T) {
|
|||
// [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, 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")
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ var (
|
|||
type worker interface {
|
||||
run()
|
||||
finish()
|
||||
when() time.Time
|
||||
lastUsedTime() time.Time
|
||||
inputFunc(func())
|
||||
inputParam(interface{})
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func (wq *workerStack) binarySearch(l, r int, expiryTime time.Time) int {
|
|||
var mid int
|
||||
for l <= r {
|
||||
mid = (l + r) / 2
|
||||
if expiryTime.Before(wq.items[mid].when()) {
|
||||
if expiryTime.Before(wq.items[mid].lastUsedTime()) {
|
||||
r = mid - 1
|
||||
} else {
|
||||
l = mid + 1
|
||||
|
|
Loading…
Reference in New Issue