Documentation
¶
Overview ¶
Package tasks provides memoized, concurrency-safe task execution.
A Task is a function that takes input, returns data (or an error), and runs at most once per Ctx/input pairing, even if invoked repeatedly.
Tasks are automatically protected from circular dependencies by Go's compile-time "initialization cycle" errors when defined as package-level variables.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
Ctx is a task execution context that memoizes results by task/input pair.
func NewCtxWithTTL ¶
NewCtxWithTTL creates a Ctx whose cached results expire after ttl. Expired entries are lazily cleaned up during cache access.
func (*Ctx) NativeContext ¶
NativeContext returns the underlying context.Context.
func (*Ctx) RunParallel ¶
RunParallel executes all provided BoundTasks concurrently, returning the first non-nil error (if any). All tasks share this Ctx's cache.
type Task ¶
type Task[I comparable, O any] struct { // contains filtered or unexported fields }
Task is a typed, memoized unit of work.
func NewTask ¶
func NewTask[I comparable, O any]( fn func(ctx *Ctx, input I) (O, error), ) *Task[I, O]
NewTask creates a Task from the provided function. Returns nil if fn is nil.
func (*Task[I, O]) Bind ¶
Bind creates a BoundTask that captures the input and an optional destination pointer for the result.