All Projects β†’ rfyiamcool β†’ gpool

rfyiamcool / gpool

Licence: other
πŸ˜€ golang goroutine pool

Programming Languages

go
31211 projects - #10 most used programming language

gpool

goroutine pool

Feature

  • resize worker num
  • worker idle timeout
  • aysnc & sync mode

Usage

package main

import (
	"fmt"
	"sync"
	"time"

	"github.com/rfyiamcool/gpool"
)

var (
	wg = sync.WaitGroup{}
)

func main() {
	gp, err := gpool.NewGPool(&gpool.Options{
		MaxWorker:   5,                 // ζœ€ε€§ηš„εη¨‹ζ•°
		MinWorker:   2,                 // ζœ€ε°ηš„εη¨‹ζ•°
		JobBuffer:   1,                 // ηΌ“ε†²ι˜Ÿεˆ—ηš„ε€§ε°
		IdleTimeout: 120 * time.Second, // εη¨‹ηš„η©Ίι—²θΆ…ζ—Άι€€ε‡Ίζ—Άι—΄
	})

	if err != nil {
		panic(err.Error())
	}

	for index := 0; index < 1000; index++ {
		wg.Add(1)
		idx := index
		gp.ProcessAsync(func() {
			fmt.Println(idx, time.Now())
			time.Sleep(1 * time.Second)
			wg.Done()
		})
	}

	wg.Done()
}
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].