Git Product home page Git Product logo

workerpool-go's People

Contributors

cmitsakis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

randydom iq-scm

workerpool-go's Issues

doesn't work with example code when using `NewPoolWithResults`

If I take the example from the documentation but I add WithResult:

func main() {
	p, _ := workerpool.NewPoolWithResults(4, func(job workerpool.Job[float64], workerID int) (int, error) {
		result := math.Sqrt(job.Payload)
		fmt.Println("result:", result)
		return 0, nil
	})
	for i := 0; i < 100; i++ {
		p.Submit(float64(i))
	}
	p.StopAndWait()

	for result := range p.Results {
		fmt.Println(result)
	}
}

the code never stops and is stuck at iteration ~3

Add progress.Writer to init/deinit

Hey there, really like your workerpool package. I am fiddling around with it to use the init/deinit feature to create a progress bar for each worker.
It might be a stupid idea to begin with (I have second thoughts), but for the sake of an argument.

An init function create a tracker:

func initWrk(workerID int) (tr *progress.Tracker, err error) { // worker init function
	tr = &progress.Tracker{
		Message: fmt.Sprintf("wrk%d", workerID),
		Units:   progress.UnitsDefault,
	}
	return tr, nil
}

The handler can increment the tracker each time it handles something...

func handler3(job workerpool.Job[Payload], workerID int, tracker *progress.Tracker) (Result, error) {
	r := Result{}
	r.Sqrt = math.Sqrt(float64(job.Payload.Num))
	time.Sleep(100 * time.Millisecond)
	tracker.Increment(1)
	return r, nil
}

My problem is that I'd need the tracker in the main function as I need to add it to the progress.Writer.

pw.AppendTracker(tracker)

Any chance I can get the init result from each worker handled up? SImilar to range p.Results?

for tracker := range p.Connections {
    pw.AppendTracker(tracker)
}

}

duplicate debug if

i read through the code to see if it may fit my needs and stumbled upon this very minor duplication in https://github.com/cmitsakis/workerpool-go/blob/master/main.go#L552

Concerning the debug statements it looks like a local struct method could clean things up.

// usage 
// => w.debug(fmt.Sprintf("[workerpool/worker%d] finished", w.id))

func (w *worker[I, O, C]) debug(msg string){
	if w.pool.loggerDebug != nil {
		LoggerDebug.Println(msg) //this should also add the \n 
	}
}

I am not a go veteran, so i had to lookup some constructs you are using and found some methods are hard to interpret/read. Especially the loop func is quite a bit of magic :-)
Still i really like the basic ideas and having it encapsulated in a tiny self-contained package is great!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.