Back to godoc.org

Package par

v1.6.2
Latest Go to latest

The latest major version is .

Published: Aug 30, 2020 | License: BSD-3-Clause | Module: github.com/rogpeppe/go-internal

Overview

Package par implements parallel execution helpers.

Index

type Cache

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

Cache runs an action once per key and caches the result.

func (*Cache) Do

func (c *Cache) Do(key interface{}, f func() interface{}) interface{}

Do calls the function f if and only if Do is being called for the first time with this key. No call to Do with a given key returns until the one call to f returns. Do returns the value returned by the one call to f.

func (*Cache) Get

func (c *Cache) Get(key interface{}) interface{}

Get returns the cached result associated with key. It returns nil if there is no such result. If the result for key is being computed, Get does not wait for the computation to finish.

type Work

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

Work manages a set of work items to be executed in parallel, at most once each. The items in the set must all be valid map keys.

func (*Work) Add

func (w *Work) Add(item interface{})

Add adds item to the work set, if it hasn't already been added.

func (*Work) Do

func (w *Work) Do(n int, f func(item interface{}))

Do runs f in parallel on items from the work set, with at most n invocations of f running at a time. It returns when everything added to the work set has been processed. At least one item should have been added to the work set before calling Do (or else Do returns immediately), but it is allowed for f(item) to add new items to the set. Do should only be used once on a given Work.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier