task

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 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 task owns one native operation's cancellation and durable completion.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCancelled         = errors.New("task cancelled")
	ErrShareStopped      = errors.New("share explicitly stopped")
	ErrApplicationClosed = errors.New("application closed")
)
View Source
var ErrInvalidSettlement = errors.New("task result violates its settlement contract")

Functions

This section is empty.

Types

type Completion

type Completion[T any] struct {
	Settlement
	Value T
}

type Config

type Config[T any] struct {
	Diagnostics         diagnostics.Sink
	ID                  ID
	Now                 func() time.Time
	Random              io.Reader
	CleanupTimeout      time.Duration
	ObservationCapacity observationstream.Capacity
	Run                 func(context.Context, Control) Completion[T]
	Completed           func(error)
	Project             func(Observation, func(Observation) bool) bool
}

type Control

type Control struct {
	Diagnostics    diagnostics.Sink
	ID             ID
	Now            func() time.Time
	Random         io.Reader
	CleanupContext func() (context.Context, context.CancelFunc)
	Emit           func(Event) bool
	StateChanged   func()
}

func (Control) NotifyStateChanged

func (control Control) NotifyStateChanged()

NotifyStateChanged follows publication of queryable workflow state. It is independent of detailed observations, whose bounded queue may drop records.

type Event

type Event interface {
	EngineEvent()
}

Event admits concrete domain observations without importing presentation types. Receivers switch on the concrete workflow event; terminal wording is not an application fact.

type FailureClass

type FailureClass uint8
const (
	FailureNone FailureClass = iota
	FailureLocal
	FailureNetwork
	FailureUsage
	FailureSourceDrift
)

type ID

type ID string

type Lifecycle

type Lifecycle struct {
	State      State
	StopReason StopReason
	// Settlement is populated only for Finished; lifecycle and outcome are independent.
	Settlement
}

func (Lifecycle) EngineEvent

func (Lifecycle) EngineEvent()

type Observation

type Observation struct {
	TaskID ID
	At     time.Time
	Event  Event
}

type Outcome

type Outcome uint8
const (
	OutcomeSuccess Outcome = iota + 1
	OutcomePartial
	OutcomePaused
	OutcomeCancelled
	OutcomeStopped
	OutcomeFailed
)

type Result

type Result[T any] struct {
	Completion[T]
	StopReason   StopReason
	StartedAt    time.Time
	FinishedAt   time.Time
	Observations observationstream.Completion
}

type Settlement

type Settlement struct {
	Outcome        Outcome
	FailureClass   FailureClass
	Failure        appobs.Failure
	CleanupFailure appobs.Failure
	// Cancellation may retain its cause without becoming a business failure.
	// Outcome, rather than Err alone, distinguishes those terminal states.
	Err          error
	CleanupError error
}

Settlement is the workflow's authoritative decision after resource cleanup. Both Wait and lifecycle observers receive this same decision; neither infers an outcome from a stop request or the presence of a low-level cause.

func (Settlement) Checked

func (settlement Settlement) Checked() Settlement

func (Settlement) Valid

func (settlement Settlement) Valid() bool

type State

type State uint8
const (
	Running State = iota + 1
	Stopping
	Finished
)

type StopReason

type StopReason uint8
const (
	NoStop StopReason = iota
	Cancelled
	ShareStopped
	ApplicationClosed
)

func Reason

func Reason(ctx context.Context) StopReason

type Task

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

func Start

func Start[T any](parent context.Context, config Config[T]) (*Task[T], error)

func (*Task[T]) Cancel

func (current *Task[T]) Cancel()

Cancel ends execution. Canceling a Wait context only detaches that waiter.

func (*Task[T]) Changes

func (current *Task[T]) Changes() <-chan struct{}

Changes returns a broadcast generation. Read it before querying state, then wait for it to close; publication between either step cannot be missed. Consumers retain no subscription and never block workflow progress.

func (*Task[T]) Done

func (current *Task[T]) Done() <-chan struct{}

func (*Task[T]) ID

func (current *Task[T]) ID() ID

func (*Task[T]) Observations

func (current *Task[T]) Observations() <-chan Observation

func (*Task[T]) State

func (current *Task[T]) State() State

func (*Task[T]) Stop

func (current *Task[T]) Stop(reason StopReason)

Stop is kept inside the engine boundary so callers can only explicitly stop a share or cancel a task, while the application owns the close reason.

func (*Task[T]) Wait

func (current *Task[T]) Wait(ctx context.Context) (Result[T], error)

Jump to

Keyboard shortcuts

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