Documentation
¶
Overview ¶
Package async provides helpers for configuring and executing asynchronous CEL functions, including drain strategies, retry, timeout, concurrency limiting, and caching wrappers.
Index ¶
- func Retry(fn functions.BlockingAsyncOp, opts ...RetryOption) functions.BlockingAsyncOp
- func RetryBinding(fn functions.BlockingAsyncOp, opts ...RetryOption) decls.OverloadOpt
- func Timeout(fn functions.BlockingAsyncOp, timeout time.Duration) functions.BlockingAsyncOp
- func TimeoutBinding(fn functions.BlockingAsyncOp, timeout time.Duration) decls.OverloadOpt
- type BlockingOp
- type Call
- type DrainAction
- type DrainStrategy
- type Observer
- type RetryOption
- type RetryableError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Retry ¶
func Retry(fn functions.BlockingAsyncOp, opts ...RetryOption) functions.BlockingAsyncOp
Retry wraps a BlockingAsyncOp with a retry policy. It will retry the operation if it returns a types.Err that wraps a RetryableError returning true for IsRetryable.
func RetryBinding ¶
func RetryBinding(fn functions.BlockingAsyncOp, opts ...RetryOption) decls.OverloadOpt
RetryBinding wraps a BlockingAsyncOp with a retry policy and returns an OverloadOpt.
func Timeout ¶
func Timeout(fn functions.BlockingAsyncOp, timeout time.Duration) functions.BlockingAsyncOp
Timeout wraps a BlockingAsyncOp with a per-call timeout.
The timeout is enforced even when the wrapped function ignores its context: the function runs on its own goroutine and Timeout selects on the deadline, returning a timeout error when it fires. A function that ignores cancellation cannot be forcibly stopped (Go cannot kill a goroutine), so its goroutine continues running in the background until it returns on its own; only its result is abandoned. This is the recommended way to bound functions that may hang or are not under the caller's control. The extra goroutine is incurred only by Timeout-wrapped calls, not by async evaluation in general.
func TimeoutBinding ¶
func TimeoutBinding(fn functions.BlockingAsyncOp, timeout time.Duration) decls.OverloadOpt
TimeoutBinding wraps a BlockingAsyncOp with a per-call timeout and returns an OverloadOpt.
Types ¶
type BlockingOp ¶
type BlockingOp = functions.BlockingAsyncOp
BlockingOp is a blocking asynchronous function operation.
type Call ¶
type Call = interpreter.AsyncCall
Call describes a pending or completed asynchronous function call. This interface exposes a safe, read-only view of the internal interpreter state.
type DrainAction ¶
type DrainAction struct {
// Reevaluate indicates that the AST should be re-evaluated immediately.
// If true, WaitDuration is ignored.
Reevaluate bool
// WaitDuration indicates how long the evaluator should wait for additional
// completions before deciding to re-evaluate. A duration of 0 means wait
// indefinitely (block on the next completion).
WaitDuration time.Duration
}
DrainAction dictates what ConcurrentEval should do after inspecting completions.
type DrainStrategy ¶
type DrainStrategy interface {
// NextAction evaluates the current state of asynchronous evaluation and
// determines the next step.
//
// - completed: The set of completions accumulated in the current batch.
// - active: The number of async calls currently launched but unresolved.
NextAction(completed []Call, active int) DrainAction
}
DrainStrategy controls when ConcurrentEval re-evaluates after async completions.
The evaluator consults the strategy each time a completion is received.
func DrainAll ¶
func DrainAll() DrainStrategy
DrainAll returns a strategy that waits for all currently pending calls to complete before re-evaluating.
Note: This strategy is optimal for independent async calls, but will over-wait if some calls depend on the results of others.
func DrainNone ¶
func DrainNone() DrainStrategy
DrainNone returns a strategy that re-evaluates after every single completion. This is the default strategy.
func DrainReady ¶
func DrainReady(debounce time.Duration) DrainStrategy
DrainReady returns a strategy that waits for a short duration after the first completion to batch any other functions that complete at roughly the same time.
type Observer ¶
type Observer = interpreter.AsyncObserver
Observer provides callbacks for monitoring the lifecycle of asynchronous function calls.
Implementations must be safe for concurrent use: the start and finish callbacks run on different goroutines, and finish callbacks for distinct calls may run concurrently. See interpreter.AsyncObserver for details.
type RetryOption ¶
type RetryOption func(*retryConfig)
RetryOption configures the behavior of RetryBinding.
func RetryAttempts ¶
func RetryAttempts(attempts int) RetryOption
RetryAttempts sets the maximum number of attempts (including the first one).
func RetryBackoff ¶
func RetryBackoff(backoff time.Duration) RetryOption
RetryBackoff sets the fixed backoff duration between attempts.
type RetryableError ¶
RetryableError is an interface that errors can implement to signal whether they are retryable.