grim

package module
v0.0.0-...-a4f5317 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2015 License: Apache-2.0 Imports: 2 Imported by: 4

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()

	// Dead returns the underlying net.Context done channel.
	Dead() <-chan struct{}
}

GrimReaper is a task runner which will wait until all the tasks are complete until continuing. 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.

Directories

Path Synopsis
Godeps
_workspace/src/golang.org/x/net/context
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.

Jump to

Keyboard shortcuts

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