goropool

package module
v0.0.0-...-199478f Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2015 License: MIT Imports: 2 Imported by: 0

README

goropool

Dead simple goroutine pool

GoDoc Build Status

Documentation

Overview

Package goropool implements a dead-simple bounded goroutine pool. It is mostly useful when dealing with blocking I/O calls.

Example
package main

import (
	"fmt"

	"github.com/CAFxX/goropool"
)

func main() {
	queue, done := goropool.NewDefaultPool()
	for i := 0; i < 10; i++ {
		queue <- func() {
			fmt.Print("*")
		}
	}
	close(queue)
	<-done
}
Output:

**********

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultPool

func NewDefaultPool() (chan<- func(), <-chan error)

NewDefaultPool creates a new goroutine pool with runtime.NumCPU() workers and a queue of size 0 (i.e. a worker must be idle for the send to the queue to succeed). See NewPool() for details about the returned values.

func NewPool

func NewPool(numWorkers, queueSize int) (chan<- func(), <-chan error)

NewPool creates and starts a bounded goroutine pool with numWorkers goroutine accepting work on a queue with queueSize elements. Each pool is made up of numWorkers+1 goroutines. NewPool returns immediately.

Two channels are returned: queue and done. The former is the channel jobs should be submitted on. A job is simply a func(). Closing the queue channel signals to the pool that no more jobs will be enqueued. Once the queue channel has been closed and all queued jobs have been completed the pool will close the second channel (done) to signal that the pool has shut down.

The done channel is of type error for future extensibility, currently no error will be returned under any circumstances. The pool makes no attempt to recover panicking jobs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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