Documentation
¶
Overview ¶
Package task owns one native operation's cancellation and durable completion.
Index ¶
- Variables
- type Completion
- type Config
- type Control
- type Event
- type FailureClass
- type ID
- type Lifecycle
- type Observation
- type Outcome
- type Result
- type Settlement
- type State
- type StopReason
- type Task
- func (current *Task[T]) Cancel()
- func (current *Task[T]) Changes() <-chan struct{}
- func (current *Task[T]) Done() <-chan struct{}
- func (current *Task[T]) ID() ID
- func (current *Task[T]) Observations() <-chan Observation
- func (current *Task[T]) State() State
- func (current *Task[T]) Stop(reason StopReason)
- func (current *Task[T]) Wait(ctx context.Context) (Result[T], error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrCancelled = errors.New("task cancelled") ErrApplicationClosed = errors.New("application closed") )
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 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 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 StopReason ¶
type StopReason uint8
const ( NoStop StopReason = iota Cancelled ApplicationClosed )
func Reason ¶
func Reason(ctx context.Context) StopReason
type Task ¶
type Task[T any] struct { // contains filtered or unexported fields }
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]) Observations ¶
func (current *Task[T]) Observations() <-chan Observation
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.