runner

package
v0.2.23 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finish

type Finish func()

type IRunner

type IRunner interface {
	Wait() error
	Stop()
}

type Runner

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

func Go

func Go(f func(s StopChan, f Finish)) (r *Runner)

Go starts the given function in a goroutine and adds the ability to stop it gracefully.

In your runner listen for the stop channel to be closed, then call finish() to stop the runner.

Example:

task := Go(func(stop StopChan, finish Finish) {
	for {
		select {
		case _, ok := <-stop:
			if !ok {
				finish()
				return
			}
		}
	}
}

func (*Runner) Stop

func (r *Runner) Stop()

Stop will signal the runner to finish the given goroutine. It is not possible to reuse a stopped runner

func (*Runner) Wait

func (r *Runner) Wait() (err error)

Wait will wait for 2 seconds for the runner to stop otherwise it returns an error

type StopChan

type StopChan <-chan struct{}

Jump to

Keyboard shortcuts

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