starlarkgroup

package module
v0.0.0-...-356d4f6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

README

starlarkgroup

GoDev test

Go errgroup.Group for starlark. Allows a starlark thread to spawn go routines. Each go routine can be optionally pooled and rate limited. Arguments to go are frozen. Wait returns a tuple of sorted values in order of calling. Calls are lazy evaluated and only executed when wait() is called.

def square(x):
    return x*x

def square_all(vs):
    # Create a group of 10 go routines, limited every 10ms with a burst of 10.
    g = group(n = 10, every = "10ms", burst = 10)
    for i in vs:
        g.go(square, i)  # args[1:] and kwargs passed to arg[0]
    return g.wait()

print(square_all(range(10)))  # prints: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Make

func Make(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Make creates a new group instance. Accepts the following optional kwargs: "n", "every", "burst".

An application can add 'group' to the Starlark envrionment like so:

globals := starlark.StringDict{
	"group": starlark.NewBuiltin("group", starlarkgroup.Make),
}

Types

type Group

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

Group implements errgroup.Group in starlark with additional rate limiting. Arguments to go call are frozen. Wait returns a sorted tuple in order of calling. Calls are lazy evaluated and only executed when waiting.

func NewGroup

func NewGroup(ctx context.Context, n int, r rate.Limit, b int) *Group

NewGroup creates a new Group with context, number of routines, rate limit and burst limit.

func (*Group) Attr

func (g *Group) Attr(name string) (starlark.Value, error)

func (*Group) AttrNames

func (g *Group) AttrNames() []string

func (*Group) Freeze

func (g *Group) Freeze()

func (*Group) Hash

func (g *Group) Hash() (uint32, error)

func (*Group) String

func (g *Group) String() string

func (*Group) Truth

func (g *Group) Truth() starlark.Bool

func (*Group) Type

func (g *Group) Type() string

Jump to

Keyboard shortcuts

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