Skip to content

Commit 7e41896

Browse files
committed
opt: calculate the interval for ReleaseTimeout() based on a default count
This PR reverts #325 to some extent.
1 parent b2374d5 commit 7e41896

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Diff for: ants.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ var (
9797
)
9898

9999
const (
100-
nowTimeUpdateInterval = 500 * time.Millisecond
101-
releaseTimeoutInterval = 100 * time.Millisecond
100+
nowTimeUpdateInterval = 500 * time.Millisecond
101+
releaseTimeoutCount = 10
102102
)
103103

104104
// Logger is used for logging formatted messages.

Diff for: pool.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,15 @@ func (p *Pool) ReleaseTimeout(timeout time.Duration) error {
299299
}
300300
p.Release()
301301

302+
interval := timeout / releaseTimeoutCount
302303
endTime := time.Now().Add(timeout)
303304
for time.Now().Before(endTime) {
304305
if p.Running() == 0 &&
305306
(p.options.DisablePurge || atomic.LoadInt32(&p.purgeDone) == 1) &&
306307
atomic.LoadInt32(&p.ticktockDone) == 1 {
307308
return nil
308309
}
309-
time.Sleep(releaseTimeoutInterval)
310+
time.Sleep(interval)
310311
}
311312
return ErrTimeout
312313
}

Diff for: pool_func.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,15 @@ func (p *PoolWithFunc) ReleaseTimeout(timeout time.Duration) error {
304304
}
305305
p.Release()
306306

307+
interval := timeout / releaseTimeoutCount
307308
endTime := time.Now().Add(timeout)
308309
for time.Now().Before(endTime) {
309310
if p.Running() == 0 &&
310311
(p.options.DisablePurge || atomic.LoadInt32(&p.purgeDone) == 1) &&
311312
atomic.LoadInt32(&p.ticktockDone) == 1 {
312313
return nil
313314
}
314-
time.Sleep(releaseTimeoutInterval)
315+
time.Sleep(interval)
315316
}
316317
return ErrTimeout
317318
}

0 commit comments

Comments
 (0)