concurrent

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package concurrent provides concurrent primitives/shortcuts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group is a Close-able thread group.

func NewGroup

func NewGroup(ctx context.Context) *Group

NewGroup initializes a new Close-able thread group.

Usage:

threads := concurrent.NewGroup(ctx)
threads.Go(func() {
  <-threads.Done() // "subscribe" for cancellation
  ...
})
err := threads.Close() // may be defer-ed etc - blocks till all threads terminate

func (*Group) Close

func (g *Group) Close() error

Close cancels context and waits for threads to terminate.

func (*Group) Done

func (g *Group) Done() <-chan struct{}

Done returns a done channel for this thread group. It should be used by goroutines to return when it's closed.

func (*Group) Go

func (g *Group) Go(f func())

Go runs func in backround. Func should return when Group.Done() channel is closed.

Jump to

Keyboard shortcuts

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