You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0 KiB
Markdown

6 years ago
# gum
6 years ago
Go Unit Manager is a simple Goroutine unit manager for GoLang.
Features:
- Scheduling of multiple goroutines.
- Subscribe to `os.Signal` events.
- Gracefull shutdown of units
## Overview
A unit is a type that implements `WorkUnit` interface. The `Spawn()` method
of registered units are run in goroutines.
The `Manager` handles communication and synchronized shutdown procedure.
## Usage
1. Create a unit manager
2. Implement the `WorkUnit` on your goroutines
3. Add units to the manager
4. Start the manager and wait on it's `Quit` channel
```golang
6 years ago
func main() {
// Create a unit manager
6 years ago
manager := gum.NewManager()
6 years ago
// Subscribe to SIGINT
6 years ago
manager.SubscribeTo(os.Interrupt)
6 years ago
6 years ago
// NewWorker returns a type implementing WorkUnit interface unit :=
NewWorker()
6 years ago
// Register the unit with the manager
6 years ago
manager.AddUnit(scheduler)
6 years ago
// Start the manager
6 years ago
go manager.Start()
6 years ago
// Wait for all units to shutdown gracefully through their `Shutdown` method
6 years ago
<-manager.Quit
6 years ago
}
```