https://github.com/titikterang/gotong-royong
to help us controll goroutine
https://github.com/titikterang/gotong-royong
concurrency concurrent-programming golang golang-examples golang-library goroutine goroutine-pool
Last synced: about 1 month ago
JSON representation
to help us controll goroutine
- Host: GitHub
- URL: https://github.com/titikterang/gotong-royong
- Owner: titikterang
- Created: 2022-03-20T05:10:57.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-20T07:07:06.000Z (about 3 years ago)
- Last Synced: 2025-01-29T22:29:54.339Z (3 months ago)
- Topics: concurrency, concurrent-programming, golang, golang-examples, golang-library, goroutine, goroutine-pool
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### Overview
gotong-royong is a simple library to help us limit goroutine### Example Code
```go
package mainimport (
"github.com/ujunglangit-id/gotong-royong/pkg"
"log"
"sync"
"time"
)func showText() {
time.Sleep(2 * time.Second)
log.Printf(
"remaining queue : %d, current channel length %d, execute current task ....\n",
wk.GetRemainingQueueLength(), wk.GetChannelLength())
}var (
wk *pkg.WorkerContainer
)func init() {
wk = pkg.NewWorkers(5)
}func main() {
wg := sync.WaitGroup{}
wk.RunInBackground()
for i := 0; i < 100; i++ {
go wk.AddNewEvent(showText)
}
wg.Add(1)
//your other logic / business flow in here
wg.Wait()
}
```