tasks

package
v0.83.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

A "Task", as used in this package, is simply a function that takes in input, returns data (or an error), and runs a maximum of one time per execution context / input value pairing, even if invoked repeatedly during the lifetime of the execution context.

Tasks are automatically protected from circular deps by Go's compile-time "initialization cycle" errors (assuming they are defined as package-level variables).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyTask

type AnyTask interface {
	RunWithAnyInput(ctx *Ctx, input any) (any, error)
}

type BoundTask

type BoundTask interface {
	Run(ctx *Ctx) error
}

type Ctx

type Ctx struct {
	// contains filtered or unexported fields
}

func NewCtx

func NewCtx(parent context.Context) *Ctx

NewCtx creates a new task execution context with no TTL. The context will cache task results indefinitely until the Ctx is discarded.

func NewCtxWithTTL

func NewCtxWithTTL(parent context.Context, ttl time.Duration) *Ctx

NewCtxWithTTL creates a new task execution context with a TTL for cached results. When ttl > 0, cached results expire after the specified duration and will be re-executed on subsequent access. Expired entries are lazily removed from memory during cache access, at most once per TTL period.

func (*Ctx) NativeContext

func (c *Ctx) NativeContext() context.Context

func (*Ctx) RunParallel

func (c *Ctx) RunParallel(tasks ...BoundTask) error

type Task

type Task[I comparable, O any] struct {
	// contains filtered or unexported fields
}

func NewTask

func NewTask[I comparable, O any](fn func(ctx *Ctx, input I) (O, error)) *Task[I, O]

func (*Task[I, O]) Bind

func (t *Task[I, O]) Bind(input I, dest *O) BoundTask

func (*Task[I, O]) Run

func (t *Task[I, O]) Run(ctx *Ctx, input I) (O, error)

func (*Task[I, O]) RunWithAnyInput

func (t *Task[I, O]) RunWithAnyInput(ctx *Ctx, input any) (any, error)

type TaskResult

type TaskResult struct {
	Data any
	Err  error
	// contains filtered or unexported fields
}

func (*TaskResult) OK

func (r *TaskResult) OK() bool

Jump to

Keyboard shortcuts

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