Socket
Socket
Sign inDemoInstall

github.com/scrapbird/gotowork

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/scrapbird/gotowork

Package gotowork implements a simple worker pool. First we create a WorkerQueue that can hold up to 5 workers Next we create 5 workers and start each one Then we add some jobs to the queue Once all work has been dispatched we tell the workers to stop Then wait for all the workers to finish the current jobs Provides a simple and easy to use worker queue.


Version published

Readme

Source

gotowork

Provides a simple and easy to use worker queue for golang.

Example

package main

import (
    "fmt"
    work "github.com/scrapbird/gotowork"
)

func main () {
    // create the workerqueue
    workerQueue := make(work.WorkerQueue, 5)

    // create and start the workers
    workers := make([]work.Worker, 5)
    for i := range workers {
        workers[i] = work.NewWorker(i, workerQueue)
        workers[i].Start()
    }

    // add some jobs
    for i := 0; i < 5; i++ {
        // get a free worker
        worker := <-workerQueue
        // give it some work
        worker <- func () {
            fmt.Println("Hello")
        }
    }

    // tell the workers to stop waiting for work
    for i := range workers {
        workers[i].Stop()
    }

    // wait for the workers to quit
    for i := range workers {
        workers[i].WaitForFinish()
    }
}

FAQs

Last updated on 02 Sep 2015

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