xxjwxc / Gowp
Licence: mit
golang worker pool , Concurrency limiting goroutine pool
Stars: ✭ 259
Labels
Projects that are alternatives of or similar to Gowp
workerpool
A workerpool that can get expanded & shrink dynamically.
Stars: ✭ 55 (-78.76%)
Mutual labels: concurrency, pool
ferryd
Fast, safe and reliable transit for the delivery of software updates to users.
Stars: ✭ 43 (-83.4%)
Mutual labels: pool
async-oneshot
A fast, small, full-featured, no-std compatible oneshot channel
Stars: ✭ 55 (-78.76%)
Mutual labels: concurrency
Python Atomicwrites
Powerful Python library for atomic file writes.
Stars: ✭ 253 (-2.32%)
Mutual labels: concurrency
gotp
(Experimental) Actors and an OTP clone, implemented in Go
Stars: ✭ 21 (-91.89%)
Mutual labels: concurrency
trading sim
📈📆 Backtest trading strategies concurrently using historical chart data from various financial exchanges.
Stars: ✭ 21 (-91.89%)
Mutual labels: concurrency
vercors
The VerCors verification toolset for verifying parallel and concurrent software
Stars: ✭ 30 (-88.42%)
Mutual labels: concurrency
awaitchannel
Go-style concurrency and channels with Python 3.5 and asyncio
Stars: ✭ 21 (-91.89%)
Mutual labels: concurrency
swoole-futures
⏳ Futures, Streams & Async/Await for PHP's Swoole asynchronous run-time.
Stars: ✭ 100 (-61.39%)
Mutual labels: concurrency
nuscr
A toolkit to manipulate Scribble-style multiparty protocols, based on classical multiparty session type theory.
Stars: ✭ 16 (-93.82%)
Mutual labels: concurrency
context-propagation
Propagate snapshots of ThreadLocal values to another thread
Stars: ✭ 15 (-94.21%)
Mutual labels: concurrency
concurrency-kit
🚄 Concurrency abstractions framework for Apple Platforms [Task, Atomic, Lock, Operation, etc.].
Stars: ✭ 17 (-93.44%)
Mutual labels: concurrency
esm
Lightweight communicating state machine framework for embedded systems
Stars: ✭ 21 (-91.89%)
Mutual labels: concurrency
golang worker pool
中文说明
- Concurrency limiting goroutine pool.
- Limits the concurrency of task execution, not the number of tasks queued.
- Never blocks submitting tasks, no matter how many tasks are queued.
- Support timeout
- Support through security queues queue
Installation
The simplest way to install the library is to run:
$ go get github.com/xxjwxc/gowp
Support the maximum number of tasks, put them in the workpool and wait for them to be completed
Example
package main
import (
"fmt"
"time"
"github.com/xxjwxc/gowp/workpool"
)
func main() {
wp := workpool.New(10) // Set the maximum number of threads
for i := 0; i < 20; i++ { // Open 20 requests
ii := i
wp.Do(func() error {
for j := 0; j < 10; j++ { // 0-10 values per print
fmt.Println(fmt.Sprintf("%v->\t%v", ii, j))
time.Sleep(1 * time.Second)
}
//time.Sleep(1 * time.Second)
return nil
})
}
wp.Wait()
fmt.Println("down")
}
Support for error return
package main
import (
"fmt"
"time"
"github.com/xxjwxc/gowp/workpool"
)
func main() {
wp := workpool.New(10) // Set the maximum number of threads
for i := 0; i < 20; i++ {
ii := i
wp.Do(func() error {
for j := 0; j < 10; j++ { // 0-10 values per print
fmt.Println(fmt.Sprintf("%v->\t%v", ii, j))
if ii == 1 {
return errors.Cause(errors.New("my test err")) // have err return
}
time.Sleep(1 * time.Second)
}
return nil
})
}
err := wp.Wait()
if err != nil {
fmt.Println(err)
}
fmt.Println("down")
}
Supporting judgement of completion (non-blocking)
package main
import (
"fmt"
"time"
"github.com/xxjwxc/gowp/workpool"
)
func main() {
wp := workpool.New(5) // Set the maximum number of threads
for i := 0; i < 10; i++ {
// ii := i
wp.Do(func() error {
for j := 0; j < 5; j++ {
//fmt.Println(fmt.Sprintf("%v->\t%v", ii, j))
time.Sleep(1 * time.Second)
}
return nil
})
fmt.Println(wp.IsDone())
}
wp.Wait()
fmt.Println(wp.IsDone())
fmt.Println("down")
}
Support synchronous waiting for results
package main
import (
"fmt"
"time"
"github.com/xxjwxc/gowp/workpool"
)
func main() {
wp := workpool.New(5) // Set the maximum number of threads
for i := 0; i < 10; i++ {
ii := i
wp.DoWait(func() error {
for j := 0; j < 5; j++ {
fmt.Println(fmt.Sprintf("%v->\t%v", ii, j))
// if ii == 1 {
// return errors.New("my test err")
// }
time.Sleep(1 * time.Second)
}
return nil
//time.Sleep(1 * time.Second)
//return errors.New("my test err")
})
}
err := wp.Wait()
if err != nil {
fmt.Println(err)
}
fmt.Println("down")
}
Support timeout exit
package main
import (
"fmt"
"time"
"time"
"github.com/xxjwxc/gowp/workpool"
)
func main() {
wp := workpool.New(5) // Set the maximum number of threads
wp.SetTimeout(time.Millisecond) // set max timeout
for i := 0; i < 10; i++ {
ii := i
wp.DoWait(func() error {
for j := 0; j < 5; j++ {
fmt.Println(fmt.Sprintf("%v->\t%v", ii, j))
time.Sleep(1 * time.Second)
}
return nil
})
}
err := wp.Wait()
if err != nil {
fmt.Println(err)
}
fmt.Println("down")
}
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].