Documentation
¶
Overview ¶
Package runner provides interruptable goroutines.
task := runner.Go(func(shouldStop runner.S) error { // NEVER returns nil in this function // do setup // defer func(){ // // do teardown // } zeroErr := errors.New("no error") for { // do some work var err error if err != nil { return err } if shouldStop() { break } } return zeroErr // any errors? }) // meanwhile... // stop the task task.Stop() // wait for it to stop (or time out) select { case <-task.StopChan(): // stopped case <-time.After(1 * time.Second): log.Fatalln("task didn't stop quickly enough") } // check errors if task.Err() != nil { log.Fatalln("task failed:", task.Err()) }
Index ¶
Constants ¶
View Source
const ( FALSE int32 = 0 TRUE int32 = 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type S ¶
type S func() bool
S is a function that will return true if the goroutine should stop executing.
type Task ¶
type Task struct { ID string // contains filtered or unexported fields }
Task represents an interruptable goroutine.
func Go ¶
Go executes the function in a goroutine and returns a Task capable of stopping the execution.
Click to show internal directories.
Click to hide internal directories.