worker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package worker defines the Worker domain contract.

Implementations (WorkerGroup, LazyWorker, PeriodicWorker) live in runtime/worker/. kernel/worker/ is the interface-only package that adapters/ may depend on without pulling in runtime implementations, preserving the adapters→kernel-only dependency rule.

ref: uber-go/fx lifecycle.go@master — Lifecycle interface defined in the public top-level package; implementations are internal. ref: go-zero core/service/servicegroup.go — Service contract separated from the group runner.

Index

Constants

This section is empty.

Variables

View Source
var ErrWorkerExitedEarly = errcode.New(errcode.KindInternal, errcode.ErrWorkerExitedEarly,
	"worker: exited early without error before context cancellation")

ErrWorkerExitedEarly is the sentinel error returned by WorkerGroup when a member Worker.Start returns nil while the group context is still live. Workers are long-running; an early successful exit is indistinguishable from a silent cancellation, and the previous behavior (record nil, leave firstErr unset) masked the abnormal state from operators. Modeling it as a typed error lets the group propagate the failure and lets callers errors.Is-check for it during shutdown reasoning.

Functions

This section is empty.

Types

type Worker

type Worker interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

Worker represents a long-running background task.

Contract:

  • Start blocks until ctx is canceled or the worker completes normally. A non-nil error signals abnormal exit. A nil return from Start while ctx is still live is itself an abnormal signal — the runtime WorkerGroup converts that into ErrWorkerExitedEarly.
  • Stop signals graceful shutdown, bounded by ctx. Should be idempotent.

Jump to

Keyboard shortcuts

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