github.com/lefelys/state (go): The state package provides simple state management primitives for go applications.  The package defines the State type, which carries errors, wait groups, shutdown signals and other values from application's background jobs.  The State type is aggregative - it contains multiple states in tree form, allowing setting dependencies for graceful shutdown between them and merging multiple independent states.  To aggregate the application's states, functions that initialize background jobs create suitable State and propagate it up in the calls stack to the layer where it will be handled, optionally merging it with other states, setting dependencies between them and annotating along the way.  Programs that use State should follow these rules to keep interfaces consistent:  1. All functions that initialize application-scoped background jobs should return State as its last return value.  There might be special cases, when returning state as the last return value is not possible, for example - when using dependency injection packages. To handle this case, embed State into dependency's return value:  2. If an error can occur during initialization it is still should be returned as State using function WithError.  3. Never return nil State - return Empty() instead, or do not return State at all if it is not needed.  4. Every background job should be shutdownable and/or waitable.
Keywords: background-jobs|graceful-shutdown|waiting