Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/cyrusaf/workerpool

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/cyrusaf/workerpool

  • v1.1.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

GoDoc Build Status

Package workerpool provides a generic workerpool implementation with basic features such as graceful shutdown and optionally dropping jobs instead of blocking when the queue is full. See the godoc page for full documenation.

Example

func main() {
	ctx := context.Background()
	wp := workerpool.WorkerPool{
		NumWorkers: 2,
		QueueSize:  10,
	}
	wp.Start(ctx) // Spawn worker goroutines and begin processing jobs

	var counter uint64 = 0 // Create counter to keep track of jobs run
	for i := 0; i < 5; i++ {
		// Enqueue job onto workerpool's job queue
		wp.Enqueue(func(ctx context.Context) {
			atomic.AddUint64(&counter, 1) // Increment counter
		})
	}
	// Gracefully shutdown workerpool, waiting for all queued jobs to finish
	wp.Shutdown()

	fmt.Println(counter)
	// Output: 5
}

FAQs

Package last updated on 16 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc