taskloop

package
v4.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package taskloop implements a task loop to run tasks sequentially in a separate Goroutine.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("the agent is closed")

ErrClosed indicates that the loop has been stopped.

Functions

This section is empty.

Types

type Loop

type Loop struct {
	// contains filtered or unexported fields
}

Loop runs submitted task serially in a dedicated Goroutine.

func New

func New(onClose func()) *Loop

New creates and starts a new task loop.

func (*Loop) Close

func (l *Loop) Close()

Close stops the loop after finishing the execution of the current task. Other pending tasks will not be executed.

func (*Loop) CloseWithPreStop added in v4.3.0

func (l *Loop) CloseWithPreStop(preStop func())

CloseWithPreStop stops the loop after finishing the execution of the current task. It calls preStop after the loop is marked closed and before waiting for the current task to return.

func (*Loop) Deadline

func (l *Loop) Deadline() (deadline time.Time, ok bool)

Deadline returns the no valid time as task loops have no deadline.

func (*Loop) Done

func (l *Loop) Done() <-chan struct{}

Done returns a channel that's closed when the task loop has been stopped.

func (*Loop) Err

func (l *Loop) Err() error

Err returns nil if the task loop is still running. Otherwise it return errClosed if the loop has been closed/stopped.

func (*Loop) Run

func (l *Loop) Run(ctx context.Context, t func(context.Context)) error

Run serially executes the submitted callback. Blocking tasks must be cancelable by context.

func (*Loop) Value

func (l *Loop) Value(any) any

Value is not supported for task loops.