Documentation
¶
Index ¶
- Variables
- func OnProgramExit(about string, fn func())
- func RootContext() context.Context
- func RootContextCanceled() <-chan struct{}
- func WaitExit(shutdownTimeout int)
- type Callback
- type Dependencies
- type Parent
- type Task
- func (t *Task) Context() context.Context
- func (t *Task) Finish(reason any)
- func (t *Task) FinishAndWait(reason any)
- func (t *Task) FinishCause() error
- 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 OnProgramExit ¶
func OnProgramExit(about string, fn func())
func RootContext ¶
func RootContextCanceled ¶
func RootContextCanceled() <-chan struct{}
func WaitExit ¶
func WaitExit(shutdownTimeout int)
WaitExit waits for a signal to shutdown the program, and then 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.
Types ¶
type Dependencies ¶ added in v0.7.0
type Dependencies[T comparable] struct { // contains filtered or unexported fields }
func NewDependencies ¶ added in v0.7.0
func NewDependencies[T comparable]() *Dependencies[T]
func (*Dependencies[T]) Add ¶ added in v0.7.0
func (w *Dependencies[T]) Add(ele T)
func (*Dependencies[T]) Delete ¶ added in v0.7.0
func (w *Dependencies[T]) Delete(ele T)
func (*Dependencies[T]) Range ¶ added in v0.7.0
func (w *Dependencies[T]) Range(yield func(T) bool)
type Parent ¶
type Parent interface {
Context() context.Context
// Subtask returns a new subtask with the given name, derived from the parent's context.
//
// This should not be called after Finish is called on the task or its parent task.
Subtask(name string, needFinish bool) *Task
Name() string
Finish(reason any)
OnCancel(name string, f func())
}
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) FinishAndWait ¶
FinishAndWait 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)
}