shutter

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

README

dfuse shutter library

reference License

Goroutines and processes shutdown management, an alternative to Contexts It is part of dfuse.

Usage

See example usage in merger

Contributing

Issues and PR in this repo related strictly to the shutter library.

Report any protocol-specific issues in their respective repositories

Please first refer to the general dfuse contribution guide, if you wish to contribute to this code base.

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShutterWasAlreadyDown = errors.New("saferun was called on an already-shutdown shutter")

Functions

This section is empty.

Types

type Option added in v1.4.1

type Option = func(shutter *Shutter)

func RegisterOnTerminated added in v1.4.1

func RegisterOnTerminated(f func(error)) Option

registers a function to be called on terminated

func RegisterOnTerminating added in v1.4.1

func RegisterOnTerminating(f func(error)) Option

registers a function to be called on terminating

type Shutter

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

func New

func New(opts ...Option) *Shutter

func (*Shutter) Err

func (s *Shutter) Err() error

func (*Shutter) IsTerminated added in v1.4.1

func (s *Shutter) IsTerminated() bool

func (*Shutter) IsTerminating added in v1.4.1

func (s *Shutter) IsTerminating() bool

func (*Shutter) LockedInit added in v1.4.1

func (s *Shutter) LockedInit(fn func() error) (err error)

LockedInit allows you to run a function only if the shutter is not down yet, with the assurance that the it will not run its callback functions during the execution of your function.

This is useful to prevent race conditions, where the func given to "LockedInit" should increase a counter and the func given to OnShutdown should decrease it.

WARNING: never call Shutdown from within your LockedInit function, it will deadlock. Also, keep these init functions as short as possible.

NOTE: This was previously named SafeRun

func (*Shutter) OnTerminated added in v1.4.1

func (s *Shutter) OnTerminated(f func(error))

OnTerminated registers an additional handler to be triggered on `Shutdown()`. These calls will be blocking and will occur when the shutter has shutdown

func (*Shutter) OnTerminating added in v1.4.1

func (s *Shutter) OnTerminating(f func(error))

OnTerminating registers an additional handler to be triggered on `Shutdown()`. These calls will be blocking and will occur when the shutter is in the process of shutting down.

func (*Shutter) Shutdown

func (s *Shutter) Shutdown(err error)

func (*Shutter) Terminated added in v1.4.1

func (s *Shutter) Terminated() <-chan struct{}

func (*Shutter) Terminating added in v1.4.1

func (s *Shutter) Terminating() <-chan struct{}

Jump to

Keyboard shortcuts

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