signalwrapper

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2016 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package signalwrapper is used to run functions that are sensitive to signals that may be received from outside the process. It can also be used as just an async function runner that is cancellable and we may abstract this further into another package in the future.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancellableFunc

type CancellableFunc func(<-chan struct{}) error

CancellableFunc is a function that cancels if it receives a message on the given channel. It must return an error if any occurred. It should return no error if it was cancelled successfully since it is assumed that this function will probably be called again at some future point since it was interrupted.

type Wrapped

type Wrapped struct {

	// ErrCh is the channel to listen for real-time events on the wrapped
	// function. A nil error sent means the execution completed without error.
	// This is an exactly once delivery channel.
	ErrCh <-chan error
	// contains filtered or unexported fields
}

Wrapped is the return value of wrapping a function. This has channels that can be used to wait for a result as well as functions to help with different behaviors.

func Run

func Run(f CancellableFunc) *Wrapped

Run wraps and runs the given cancellable function and returns the Wrapped struct that can be used to listen for events, cancel on other events (such as timeouts), etc.

func (*Wrapped) Cancel

func (w *Wrapped) Cancel() error

Cancel stops the running function and blocks until it returns. The resulting value is returned.

It is safe to call this multiple times. This will return the resulting error value each time.

func (*Wrapped) Wait

func (w *Wrapped) Wait() error

Wait waits for the completion of the wrapped function and returns the result.

This can be called multiple times safely.

Jump to

Keyboard shortcuts

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