Documentation
¶
Index ¶
Constants ¶
const ( // RingCritical is the highest priority, it will get canceled last RingCritical = Ring0 // RingMajor is the second highest priority, it will get canceled before RingCritical RingMajor = Ring1 // RingNormal is the third highest priority, it will get canceled before RingMajor RingNormal = Ring2 // RingMinor is the lowest priority, it will get canceled first RingMinor = Ring3 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ding ¶
type Ding struct {
// contains filtered or unexported fields
}
Ding is a struct that manages multiple rings of tasks with different priorities. Each ring has its own context and wait group.
func New ¶
New creates a new Ding instance with the provided context. It initializes the rings and starts a goroutine to handle cancellation when the context is done.
func (*Ding) Go ¶
Go starts a new goroutine for the provided function f with the context of the specified ring. It works in the same way the standard library's sync.WaitGroup works, but it also takes into account the priority of the ring and cancels the context of the ring when the main context is done. Unlike the standard library's sync.WaitGroup, Ding's Go function also provides the f function with a context to watch so it can gracefully shutdown.
type Ring ¶
type Ring int
Ring represents the priority of a task. Lower numbers indicate higher priority meaning they will be canceled later. For example, Ring 0 is the highest priority and will be canceled last, while Ring 3 is the lowest priority and will be canceled first.
const ( // Ring 0 is the highest priority, it will get canceled last Ring0 Ring = iota // Ring 1 is the second highest priority, it will get canceled before Ring 0 Ring1 // Ring 2 is the third highest priority, it will get canceled before Ring 1 Ring2 // Ring 3 is the lowest priority, it will get canceled first Ring3 )
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Command basic demonstrates the smallest useful ding setup: a couple of background workers that are cancelled and drained when the program shuts down.
|
Command basic demonstrates the smallest useful ding setup: a couple of background workers that are cancelled and drained when the program shuts down. |
|
rings
command
Command rings demonstrates how ding shuts workers down in priority order.
|
Command rings demonstrates how ding shuts workers down in priority order. |