grim

package
v0.0.0-...-cc25aa6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: Apache-2.0, Apache-2.0 Imports: 2 Imported by: 0

README

grim

A simplified interface for managing goroutines

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GrimReaper

type GrimReaper interface {
	// New creates a sub-reaper which is attached to the parent context. If
	// the parent context is killed, so are the children. However, Wait must
	// still be called for child reapers.
	New() GrimReaper

	// SpawnFunc starts a new goroutine for the given function. The task should
	// return as soon as possible after the context completes.
	SpawnFunc(TaskFunc)

	// Spawn starts a new goroutine for the given Task. The task should
	// return as soon as possible after the context completes.
	Spawn(Task)

	// Kill sends a message to all running tasks to stop. If child reapers
	// have also been created, they will be triggered to stop as well.
	Kill()

	// Wait will block until all tasks have completed. This will NOT block
	// until chlid reapers are finished. Each reaper must call wait
	// independently.
	Wait()
}

GrimReaper is a task runner which will wait until all the tasks are complete until comtinuing. Reapers can also kill tasks prematurely if they are listening to the given context.

func Reaper

func Reaper() GrimReaper

Reaper returns an implementation of the GrimReaper interface.

func ReaperWithContext

func ReaperWithContext(c context.Context) GrimReaper

ReaperWithContext creates a new GrimReaper implementation and uses the given context as the parent context.

type Task

type Task interface {
	Execute(context.Context)
}

type TaskFunc

type TaskFunc func(context.Context)

TaskFunc is a killable function which runs in a separate go routine. In order to fulfill the contract the function MUST listen to the context and exit if it fires.

Jump to

Keyboard shortcuts

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