chore: rename the method 'when' of worker to 'lastUsedTime'

This commit is contained in:
Andy Pan 2023-03-23 15:16:21 +08:00
parent e425c7b917
commit 55e222d20f
6 changed files with 7 additions and 7 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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")
}

View File

@ -16,7 +16,7 @@ var (
type worker interface {
run()
finish()
when() time.Time
lastUsedTime() time.Time
inputFunc(func())
inputParam(interface{})
}

View File

@ -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