sempool

package module
v0.0.0-...-a03d0c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 0 Imported by: 11

README

This project has been archived.

Please use something like github.com/sourcegraph/conc instead.


go-sempool -- go-sempool is a super simple semaphore go-routine worker pool

🔗 Table of Contents

What

go-sempool is a simple semaphore go-routine worker pool for Go.

  • Very basic. Does not attempt to force you to use workers in a specific way.
  • Lightweight. Does not add additional overhead.
  • Uses go-routines, and through an easy interface.
$ go get -u github.com/lrstanley/go-sempool@latest

🙋♂ Support & Assistance

  • ❤ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 🙋♂ Take a look at the support document on guidelines for tips on how to ask the right questions.
  • 🐞 For all features/bugs/issues/questions/etc, head over here.

🤝 Contributing

  • ❤ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 📋 Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
  • 🗝 For anything security related, please review this repositories security policy.

⚖ License

MIT License

Copyright (c) 2016 Liam Stanley <me@liamstanley.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Also located here

Documentation

Overview

Package sempool provides a very lightweight goroutine work pool

Here is an example, which creates no more than 5 go-routines at a time. Once the as each go-routine finishes, a slot is opened, which is then occupied by the next available piece of work:

concurrency := 5
pool := sempool.New(concurrency)
urls := []string{"url1", "url2"}
for _, url := range urls {
 	pool.Slot() // wait for an open slot
 	go func(url) {
 	 	defer pool.Free() // free the slot we're occupying

 	 	// get url or other stuff
 	}(url)
}

pool.Wait()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool represents a go-routine worker pool. This does NOT manage the workers, only how many workers are running.

func New

func New(count int) Pool

New returns a new Pool{} method

func (*Pool) Free

func (p *Pool) Free()

Free is used to free the slot taken by Pool.Slot()

func (*Pool) Slot

func (p *Pool) Slot()

Slot is used to wait for an open slot to start processing

func (*Pool) Wait

func (p *Pool) Wait()

Wait is used to wait for all open Slot()'s to be Free()'d

func (*Pool) WaitChan

func (p *Pool) WaitChan() chan struct{}

WaitChan returns a channel that can be used to wait for a response to a channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL