From 55e222d20f1eb667d87b9c1edf1a51ac4d25ecd7 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Thu, 23 Mar 2023 15:16:21 +0800 Subject: [PATCH] chore: rename the method 'when' of worker to 'lastUsedTime' --- worker.go | 2 +- worker_func.go | 2 +- worker_loop_queue.go | 4 ++-- worker_loop_queue_test.go | 2 +- worker_queue.go | 2 +- worker_stack.go | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/worker.go b/worker.go index 379a875..887bb98 100644 --- a/worker.go +++ b/worker.go @@ -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 } diff --git a/worker_func.go b/worker_func.go index 0743506..701a076 100644 --- a/worker_func.go +++ b/worker_func.go @@ -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 } diff --git a/worker_loop_queue.go b/worker_loop_queue.go index 89e8112..e8f481f 100644 --- a/worker_loop_queue.go +++ b/worker_loop_queue.go @@ -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 diff --git a/worker_loop_queue_test.go b/worker_loop_queue_test.go index 5dac504..c5ad8a9 100644 --- a/worker_loop_queue_test.go +++ b/worker_loop_queue_test.go @@ -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") } diff --git a/worker_queue.go b/worker_queue.go index b0da75d..3792a55 100644 --- a/worker_queue.go +++ b/worker_queue.go @@ -16,7 +16,7 @@ var ( type worker interface { run() finish() - when() time.Time + lastUsedTime() time.Time inputFunc(func()) inputParam(interface{}) } diff --git a/worker_stack.go b/worker_stack.go index f8c7fa9..418dbf1 100644 --- a/worker_stack.go +++ b/worker_stack.go @@ -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