https://github.com/txthinking/runnergroup
RunnerGroup is like sync.WaitGroup, the diffrence is if one task stops, all will be stopped.
https://github.com/txthinking/runnergroup
blocking golang goroutine server sync waitgroup
Last synced: 2 months ago
JSON representation
RunnerGroup is like sync.WaitGroup, the diffrence is if one task stops, all will be stopped.
- Host: GitHub
- URL: https://github.com/txthinking/runnergroup
- Owner: txthinking
- License: mit
- Created: 2020-03-21T10:46:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-24T02:13:07.000Z (5 months ago)
- Last Synced: 2025-03-31T17:07:22.188Z (3 months ago)
- Topics: blocking, golang, goroutine, server, sync, waitgroup
- Language: Go
- Homepage: https://www.txthinking.com
- Size: 19.5 KB
- Stars: 21
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## RunnerGroup
[](https://godoc.org/github.com/txthinking/runnergroup)
[](https://github.com/txthinking/runnergroup/blob/master/LICENSE)RunnerGroup is like [sync.WaitGroup](https://pkg.go.dev/sync?tab=doc#WaitGroup), the diffrence is if one task stops, all will be stopped.
❤️ A project by [txthinking.com](https://www.txthinking.com)
### Install
$ go get github.com/txthinking/runnergroup
### Example
```
import (
"context"
"log"
"net/http"
"time""github.com/txthinking/runnergroup"
)func Example() {
g := runnergroup.New()s := &http.Server{
Addr: ":9991",
}
g.Add(&runnergroup.Runner{
Start: func() error {
return s.ListenAndServe()
},
Stop: func() error {
return s.Shutdown(context.Background())
},
})s1 := &http.Server{
Addr: ":9992",
}
g.Add(&runnergroup.Runner{
Start: func() error {
return s1.ListenAndServe()
},
Stop: func() error {
return s1.Shutdown(context.Background())
},
})go func() {
time.Sleep(5 * time.Second)
log.Println(g.Done())
}()
log.Println(g.Wait())
// Output:
}```
## License
Licensed under The MIT License