Skip to content

titikterang/gotong-royong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

gotong-royong is a simple library to help us limit goroutine

Example Code

package main

import (
	"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()
}