Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hanjm/timerpool
timer pool for high performance time out control (pooled time.AfterFunc/time.NewTimer)
https://github.com/hanjm/timerpool
pool timeout timerpool
Last synced: about 1 month ago
JSON representation
timer pool for high performance time out control (pooled time.AfterFunc/time.NewTimer)
- Host: GitHub
- URL: https://github.com/hanjm/timerpool
- Owner: hanjm
- License: mit
- Created: 2019-12-02T13:27:46.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-02T14:01:11.000Z (about 5 years ago)
- Last Synced: 2024-10-14T18:52:56.958Z (2 months ago)
- Topics: pool, timeout, timerpool
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![GoDoc](https://godoc.org/github.com/hanjm/timerpool?status.svg)](https://godoc.org/github.com/hanjm/timerpool)
[![Go Report Card](https://goreportcard.com/badge/github.com/hanjm/timerpool)](https://goreportcard.com/report/github.com/hanjm/timerpool)
[![code-coverage](http://gocover.io/_badge/github.com/hanjm/timerpool)](http://gocover.io/github.com/hanjm/timerpool)# timerpool
timer pool for high performance time out control (pooled time.AfterFunc/time.NewTimer)use example with context
```go
ctx, cancel := context.WithCancel(parentCtx)
t := GetTimerWithAfterFunc(time.Second*5, cancel)
PutTimerWithAfterFunc(t)
cancel()
```
use example with timer.C
```go
timer:=GetTimer(time.Second*5)
select {
case <-timer.C:
// timeout
PutTimer(timer)
return
// other case ...
}
PutTimer(timer)
```
benchmark result
```
go test -run TimeoutControl -bench TimeoutControl
goos: darwin
goarch: amd64
BenchmarkTimeoutControlViaContextWithTimeout-8 2272261 523 ns/op
BenchmarkTimeoutControlViaContextWithCancelAndRawTimer-8 4370292 267 ns/op
BenchmarkTimeoutControlViaContextWithCancelAndTimerPool-8 4662602 253 ns/op
BenchmarkTimeoutControlViaRawTimer-8 4829988 245 ns/op
BenchmarkTimeoutControlViaTimerPool-8 9144037 126 ns/op
```