singleflight

package
v0.0.0-...-417428f Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: MIT, Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package singleflight based on github.com/golang/groupcache/singleflight

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

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

Call represents single deduplicated function call.

func (*Call) Do

func (c *Call) Do(fn func() interface{}) interface{}

type Group

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

Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.

func (*Group) Do

func (g *Group) Do(key interface{}, fn func() interface{}) interface{}

Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.

func (*Group) DoAsync

func (g *Group) DoAsync(key interface{}, fn func() interface{})

DoAsync used instead of Do, when there is not need to wait for result. It behaves like go { Group.Do(key, fn) }(), but doesn't create goroutine when there is another execution for given key in-flight.

Jump to

Keyboard shortcuts

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