Documentation
¶
Index ¶
- Variables
- func DebugTaskList() []string
- func GracefulShutdown(timeout time.Duration) (err error)
- func OnProgramExit(about string, fn func())
- func RootContext() context.Context
- func RootContextCanceled() <-chan struct{}
- type Callback
- type Parent
- type Task
- func (t *Task) Context() context.Context
- func (t *Task) Finish(reason any)
- func (t *Task) FinishCause() error
- func (t *Task) Finished() <-chan struct{}
- func (t *Task) MarshalText() ([]byte, error)
- func (t *Task) Name() string
- func (t *Task) OnCancel(about string, fn func())
- func (t *Task) OnFinished(about string, fn func())
- func (t *Task) String() string
- func (t *Task) Subtask(name string, needFinish ...bool) *Task
- type TaskFinisher
- type TaskStarter
Constants ¶
This section is empty.
Variables ¶
var ErrProgramExiting = errors.New("program exiting")
Functions ¶
func DebugTaskList ¶
func DebugTaskList() []string
DebugTaskList returns list of all tasks.
The returned string is suitable for printing to the console.
func GracefulShutdown ¶
GracefulShutdown waits for all tasks to finish, up to the given timeout.
If the timeout is exceeded, it prints a list of all tasks that were still running when the timeout was reached, and their current tree of subtasks.
func OnProgramExit ¶
func OnProgramExit(about string, fn func())
func RootContext ¶
func RootContextCanceled ¶
func RootContextCanceled() <-chan struct{}
Types ¶
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task controls objects' lifetime.
Objects that uses a Task should implement the TaskStarter and the TaskFinisher interface.
Use Task.Finish to stop all subtasks of the Task.
func (*Task) Finish ¶
Finish cancel all subtasks and wait for them to finish, then marks the task as finished, with the given reason (if any).
func (*Task) FinishCause ¶
FinishCause returns the reason / error that caused the task to be finished.
func (*Task) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Task) OnCancel ¶
OnCancel calls fn when the task is canceled.
It should not be called after Finish is called.
func (*Task) OnFinished ¶
OnFinished calls fn when the task is canceled and all subtasks are finished.
It should not be called after Finish is called.
type TaskFinisher ¶
type TaskFinisher interface {
Finish(reason any)
}