shutter

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: Apache-2.0 Imports: 2 Imported by: 89

README

StreamingFast shutter library

reference License

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

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 StreamingFast contribution guide, if you wish to contribute to this code base.

This codebase uses unit tests extensively, please write and run tests.

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

type Option = func(shutter *Shutter)

func RegisterOnTerminated

func RegisterOnTerminated(f func(error)) Option

registers a function to be called on terminated

func RegisterOnTerminating

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

func (s *Shutter) IsTerminated() bool

func (*Shutter) IsTerminating

func (s *Shutter) IsTerminating() bool

func (*Shutter) LockedInit

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

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

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

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

func (*Shutter) Terminating

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

Jump to

Keyboard shortcuts

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