Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( moerr.NewInternalErrorNoCtx("runner is unavailable") )ErrUnavailable =
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
Option stop option
func WithStopTimeout ¶
WithStopTimeout the stopper will print the names of tasks that are still running beyond this timeout.
type Stopper ¶
type Stopper struct {
// contains filtered or unexported fields
}
Stopper a stopper used to to manage all tasks that are executed in a separate goroutine, and Stopper can manage these goroutines centrally to avoid leaks. When Stopper's Stop method is called, if some tasks do not exit within the specified time, the names of these tasks will be returned for analysis.
func (*Stopper) GetTaskCount ¶
GetTaskCount returns number of the running task
func (*Stopper) RunNamedTask ¶
RunNamedTask run a task that can be cancelled. ErrUnavailable returned if stopped is not running Example:
err := s.RunNamedTask("named task", func(ctx context.Context) { select { case <-ctx.Done(): // cancelled case <-time.After(time.Second): // do something } }) if err != nil { // hanle error return }
func (*Stopper) RunTask ¶
RunTask run a task that can be cancelled. ErrUnavailable returned if stopped is not running See also `RunNamedTask` Example:
err := s.RunTask(func(ctx context.Context) { select { case <-ctx.Done(): // cancelled case <-time.After(time.Second): // do something } }) if err != nil { // hanle error return }