eventloop

package
v0.0.0-...-fa598ba Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminatedError

func IsTerminatedError(errIn error) bool

IsTerminatedError checks whether task enters a terminated state, which include finished, canceled

Types

type Runner

type Runner[T Task] struct {
	// contains filtered or unexported fields
}

Runner runs a Task.

func NewRunner

func NewRunner[T Task](t T) *Runner[T]

NewRunner returns a new Runner.

func (*Runner[R]) Run

func (r *Runner[R]) Run(ctx context.Context) error

Run is called by the runtime. Cancelling the ctx cancels the task immediately and forcefully.

type Task

type Task interface {
	// Init is called before entering the loop calling Poll.
	Init(ctx context.Context) error

	// Poll should be called periodically until an error is returned.
	Poll(ctx context.Context) error

	// NotifyExit does necessary bookkeeping job for exiting,
	// such as notifying a master.
	// errIn describes the reason for exiting.
	NotifyExit(ctx context.Context, errIn error) error

	// Close does necessary clean up.
	// TODO `ctx` is for compatibility, remove it.
	Close(ctx context.Context) error

	// Stop is called when a task is canceled
	Stop(ctx context.Context) error

	// ID returns an identifier for the Task.
	ID() string
}

Task defines the common methods used to drive both workers and masters. It will replace the current `Worker` interface in further refactors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL