55[ ![ Coverage] ( _icons/coverage.svg )] ( ./_icons/coverage.svg )
66![ Test] ( https://github.com/FishGoddess/goes/actions/workflows/test.yml/badge.svg )
77
8- ** Goes** is a easy-to-use and lightweight lib for limiting goroutines .
8+ ** Goes** is a easy-to-use and lightweight lib for executing async tasks .
99
1010[ 阅读中文版的文档] ( ./README.md )
1111
1212### 🥇 Features
1313
14- * Spin lock with backoff strategy.
15- * Limiter only limits the number of simultaneous goroutines, not reuses goroutines.
14+ * Supports spin lock with backoff strategy.
15+ * Limits the number of simultaneous goroutines and not reuses them by Limiter.
16+ * Limits the number of simultaneous goroutines and reuses them by Executor.
1617
1718_ Check [ HISTORY.md] ( ./HISTORY.md ) and [ FUTURE.md] ( ./FUTURE.md ) to know about more information._
1819
@@ -33,16 +34,28 @@ import (
3334)
3435
3536func main () {
37+ // Limits the number of simultaneous goroutines and not reuses them.
3638 limiter := goes.NewLimiter (4 )
3739
38- for i := 0 ; i < 100 ; i++ {
40+ for i := 0 ; i < 20 ; i++ {
3941 limiter.Go (func () {
40- fmt.Println (time.Now ())
41- time.Sleep (100 * time.Millisecond )
42+ fmt.Println (" limiter --> " , time.Now ())
43+ time.Sleep (time.Second )
4244 })
4345 }
4446
4547 limiter.Wait ()
48+
49+ // Limits the number of simultaneous goroutines and reuses them.
50+ executor := goes.NewExecutor (4 )
51+ defer executor.Close ()
52+
53+ for i := 0 ; i < 20 ; i++ {
54+ executor.Submit (func () {
55+ fmt.Println (" executor --> " , time.Now ())
56+ time.Sleep (time.Second )
57+ })
58+ }
4659}
4760```
4861
@@ -60,15 +73,15 @@ goarch: amd64
6073cpu: AMD EPYC 7K62 48-Core Processor
6174
6275BenchmarkLimiter-2 2417040 498.5 ns/op 24 B/op 1 allocs/op
63- BenchmarkPool-2 23793781 49.9 ns/op 0 B/op 0 allocs/op
76+ BenchmarkExecutor-2 23793781 49.9 ns/op 0 B/op 0 allocs/op
6477BenchmarkAntsPool-2 4295964 271.7 ns/op 0 B/op 0 allocs/op
6578
6679BenchmarkLimiterTime-2: num is 1000000, cost is 300.936441ms
67- BenchmarkPoolTime -2: num is 1000000, cost is 51.350509ms
80+ BenchmarkExecutorTime -2: num is 1000000, cost is 51.350509ms
6881BenchmarkAntsPoolTime-2: num is 999744, cost is 346.972287ms
6982```
7083
71- > Obviously, goes.Pool is 5x faster than ants.Pool which has more features, so try goes if you prefer a lightweight and faster pool .
84+ > Obviously, goes.Executor is 5x faster than ants.Pool which has more features, so try goes if you prefer a lightweight and faster executor .
7285
7386> Benchmarks: [ _ examples/performance_test.go] ( ./_examples/performance_test.go ) .
7487
0 commit comments