Documentation
¶
Index ¶
- type Controller
- func (c *Controller) Die() bool
- func (c *Controller) Go(g Goroutine) *Controller
- func (c *Controller) GoWithRecover(g Goroutine, rf Recover) *Controller
- func (c *Controller) Shutdown()
- func (c *Controller) Wait()
- func (c *Controller) WithDeadline(deadline time.Time) *Controller
- func (c *Controller) WithTimeout(timeout time.Duration) *Controller
- func (c *Controller) WithValue(key interface{}, value interface{}) *Controller
- type Deadliner
- type Goroutine
- type Prioritier
- type PriorityQueue
- type Recover
- type TimeoutChan
- type TimeoutChanStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶ added in v1.0.0
type Controller struct {
// contains filtered or unexported fields
}
Controller implements a simple controller of goroutines, which can cancel or wait for all under control goroutines to return.
func NewController ¶ added in v1.0.0
func NewController(ctx context.Context, name string) *Controller
NewController creates a new goproc Controller.
func (*Controller) Die ¶ added in v1.0.0
func (c *Controller) Die() bool
Die tells whether c is already cancelled - it always returns true after the first time c.Shutdown() or c.Wait() is called.
func (*Controller) Go ¶ added in v1.0.0
func (c *Controller) Go(g Goroutine) *Controller
Go initiates a new goroutine for g and gains control on the goroutine through a context.Context argument.
func (*Controller) GoWithRecover ¶ added in v1.0.0
func (c *Controller) GoWithRecover(g Goroutine, rf Recover) *Controller
GoWithRecover initiates a new goroutine for g and gains control on the goroutine through a context.Context argument. Any panic from g will be captured and handled by rf.
func (*Controller) Shutdown ¶ added in v1.0.0
func (c *Controller) Shutdown()
Shutdown cancels and waits for any goroutine under control.
func (*Controller) Wait ¶ added in v1.0.0
func (c *Controller) Wait()
Wait waits for any goroutine under control to exit.
func (*Controller) WithDeadline ¶ added in v1.0.0
func (c *Controller) WithDeadline(deadline time.Time) *Controller
WithDeadline returns a copy of c with deadline set to internal context object, which will be passed to the Goroutine functions in subsequent c.Go* calls.
Note that unlike a child context, the returned object still holds the control of c, which means cancelling the returned Controller would actually cancel all goroutines started by c.
func (*Controller) WithTimeout ¶ added in v1.0.0
func (c *Controller) WithTimeout(timeout time.Duration) *Controller
WithTimeout returns a copy of c with timeout set to internal context object, which will be passed to the Goroutine functions in subsequent c.Go* calls.
Note that unlike a child context, the returned object still holds the control of c, which means cancelling the returned Controller would actually cancel all goroutines started by c.
func (*Controller) WithValue ¶ added in v1.0.0
func (c *Controller) WithValue(key interface{}, value interface{}) *Controller
WithValue returns a copy of c with key->value added to internal context object, which will be passed to the Goroutine functions in subsequent c.Go* calls. For good practice of context key-value usage, reference context package docs.
Note that unlike a child context, the returned object still holds the control of c, which means cancelling the returned Controller would actually cancel all goroutines started by c.
type Deadliner ¶
Deadliner is the interface implemented by an object that can return a deadline time.
type Prioritier ¶
type Prioritier interface {
Priority() int64
}
Prioritier is the interface implemented by an object that can return a int64 priority.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue is heap-implementation of priority queue.
func NewPriorityQueue ¶
func NewPriorityQueue(desc bool, size int) *PriorityQueue
NewPriorityQueue creates a new PriorityQueue.
func (PriorityQueue) Len ¶
func (q PriorityQueue) Len() int
Len implements Len method of sort.Interface.
func (PriorityQueue) Less ¶
func (q PriorityQueue) Less(i, j int) bool
Less implements Less method of sort.Interface.
func (*PriorityQueue) Peek ¶
func (q *PriorityQueue) Peek() interface{}
Peek returns the top element of the priority queue. User should ensure the queue is not empty before calling Peek.
func (*PriorityQueue) Pop ¶
func (q *PriorityQueue) Pop() interface{}
Pop implements Pop method of heap.Interface.
func (*PriorityQueue) Push ¶
func (q *PriorityQueue) Push(x interface{})
Push implements Push method of heap.Interface.
func (PriorityQueue) Swap ¶
func (q PriorityQueue) Swap(i, j int)
Swap implements Swap method of sort.Interface.
type Recover ¶ added in v1.0.0
type Recover func(r interface{})
Recover defines the recover handler function type for Controller.
type TimeoutChan ¶
type TimeoutChan struct { In chan<- Deadliner Out <-chan Deadliner // contains filtered or unexported fields }
TimeoutChan is a type representing a channel for Deadliner objects. TimeoutChan accepts Deadliner from TimeoutChan.In and sends Deadliner to Timeout.Out when its deadline is reached.
func NewTimeoutChan ¶
NewTimeoutChan creates a new TimeoutChan. With 0 limit an unlimited timeout chan will be returned.
func (*TimeoutChan) Clear ¶
func (c *TimeoutChan) Clear() int
Clear clears buffered Deadliners in TimeoutChan.
func (*TimeoutChan) Close ¶
func (c *TimeoutChan) Close()
Close closes TimeoutChan and waits until all buffered Deadliners in TimeoutChan to be sent and read in TimeoutChan.Out before it returns.
func (*TimeoutChan) Push ¶
func (c *TimeoutChan) Push(in Deadliner)
Push is an alias of TimeoutChan.In <- (in Deadliner), but bypasses background push process for unlimited TimeoutChan.
func (*TimeoutChan) Shutdown ¶
func (c *TimeoutChan) Shutdown()
Shutdown closes TimeoutChan and returns immediately, any buffered Deadliners in TimeoutChan will be ignored.
func (*TimeoutChan) Stats ¶ added in v0.0.2
func (c *TimeoutChan) Stats() TimeoutChanStats
Stats returns TimeoutChan statistics.
type TimeoutChanStats ¶
TimeoutChanStats contains timeout chan statistics returned from TimeoutChan.Stats().
func (TimeoutChanStats) String ¶
func (s TimeoutChanStats) String() string
String implements fmt.Stringer.