You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/hatchify/queue

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hatchify/queue

v0.4.81
Source
Go
Version published
Created
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

Package last updated on 09 Oct 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