Socket
Socket
Sign inDemoInstall

github.com/hatchify/queue

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/hatchify/queue


Version published

Readme

Source

queue

queue is a threaded job library. It allows for an easy way to cap a batch of actions to a given number of goroutines. Reducing the overhead associated with spinning up a new goroutine.

Usage

Queue.New


func ExampleQueue_New() {
	var wg sync.WaitGroup
	// Initialize a queue with two threads and a length of four
	q := New(2, 4)
	// Set waitgroup for eight jobs
	wg.Add(8)

	// Iterate eight times
	for i := 0; i < 8; i++ {
		// Create job with a closure to maintain the value of i
		job := func(i int) Job {
			// Return job
			return func() {
				// Print our stored i value
				fmt.Printf("Job %d\n", i)
				// Notify waitgroup that we have finished our task
				wg.Done()
			}
		}(i)

		// Push job into queue
		q.New(job)
	}

	// Wait until all of our jobs have finished
	wg.Wait()
}

FAQs

Last updated on 09 Oct 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc