Skip to content

cst05001/goroutinepool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

a goroutine pool

老龚 said goroutine pool is meaningless, but I still wrote one.

usage

package main

import (
    "github.com/cst05001/goroutinepool"
    "log"
    "fmt"
    "time"
)

type MyJob struct {
    I   int
}

func (this *MyJob) Do(executer *goroutinepool.Executer) {
    log.Print(fmt.Sprintf("#%d: MyJob.Do() start\n", executer.Id))
    fmt.Printf("Hello, %d\n", this.I)
    time.Sleep(time.Second * 5)
    log.Print(fmt.Sprintf("#%d: MyJob.Do() end\n", executer.Id))
}

func processor() {
    pool := *goroutinepool.NewPool(4)
    for i := 0; i < 10; i++ {
        executer := pool.GetExecuter()
        go executer.Execute(&MyJob{I: i})
    }
}

func main() {
    go processor()
    time.Sleep(time.Second * 30)
}

output

screenshot1

About

a goroutine pool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages