Skip to content

mengdu/gopool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gopool

A lightweight goroutine pool for Golang.

Reference Implementation

go get github.com/mengdu/gopool

Usage

package main

import (
	"fmt"
	"time"

	"github.com/mengdu/gopool"
)

func main() {
	pool := gopool.New(3)
	defer pool.Release()
	for i := 0; i < 10; i++ {
		index := i
		// fmt.Printf("task-%d\n", index)
		pool.Schedule(func() {
			fmt.Println("do", index)
			time.Sleep(time.Second * 2) // Simulate time-consuming tasks
		})
	}
	pool.Wait() // Wait for all tasks to complete
	fmt.Println("all done")
}

About

A lightweight goroutine pool for Golang.

Resources

License

Stars

Watchers

Forks

Languages