Top 5.8% dependent packages on proxy.golang.org
Top 4.7% dependent repos on proxy.golang.org
Top 0.7% docker downloads on proxy.golang.org
proxy.golang.org : github.com/lefelys/state
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.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/lefelys/state
Keywords:
background-jobs
, graceful-shutdown
, waiting
License: MIT
Latest release: almost 5 years ago
First release: over 5 years ago
Namespace: github.com/lefelys
Dependent packages: 1
Dependent repositories: 1
Stars: 12 on GitHub
Forks: 0 on GitHub
Docker dependents: 1
Docker downloads: 150,606
See more repository details: repos.ecosyste.ms
Last synced: 20 days ago