Documentation
¶
Overview ¶
Package async provides a concurrency-limited runtime for executing potentially slow checks (registry access, network, filesystem) in a controlled, cancellable way.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterResolver ¶
func RegisterResolver(r Resolver)
RegisterResolver adds a resolver to the global registry.
Types ¶
type CheckRequest ¶
type CheckRequest struct {
// RuleCode identifies the rule that created this request.
RuleCode string
// Category classifies the I/O type (reserved for future per-category routing).
Category Category
// Key is a fully-specific cache/dedupe key encoding ref+platform+options.
// Requests with the same (ResolverID, Key) are deduplicated.
Key string
// ResolverID routes to a registered Resolver implementation.
ResolverID string
// Data is resolver-specific typed input.
Data any
// Timeout is a per-request budget. Zero means use global timeout only.
Timeout time.Duration
// Handler converts resolved data into violations.
Handler ResultHandler
// File is the source file this request is associated with.
File string
// StageIndex identifies the stage this request is for (used for merging).
StageIndex int
}
CheckRequest declares a planned unit of async work.
type CompletedCheck ¶
CompletedCheck records a successfully completed async check (even if it produced zero violations). Used by the merge logic to know which fast-path violations should be replaced.
type ResolutionKey ¶
ResolutionKey identifies a unique resolution unit in a runtime session. It matches the runtime's internal (ResolverID, Key) dedupe key.
type Resolver ¶
type Resolver interface {
// ID returns the unique identifier for this resolver.
ID() string
// Resolve executes the async operation. data is the resolver-specific input
// from CheckRequest.Data. The returned value is passed to ResultHandler.OnSuccess.
Resolve(ctx context.Context, data any) (any, error)
}
Resolver fulfills async check requests.
func GetResolver ¶
GetResolver returns the resolver with the given ID, or nil.
type ResultHandler ¶
ResultHandler processes a resolved result and returns violations. The return value is opaque to the runtime; the caller (lint.go) casts it to []rules.Violation. This avoids an import cycle between async and rules.
Return semantics:
- nil: handler could not process this value (e.g., wrong type); the runtime will NOT mark this handler's request as completed.
- non-nil (including empty slice): handler processed the value; the runtime marks it as completed, replacing fast-path violations.
type RunResult ¶
type RunResult struct {
// Violations is a flat list of opaque violation values.
// The caller casts these to rules.Violation.
Violations []any
Skipped []Skipped
// Completed records every (rule, file, stage) that resolved successfully.
Completed []CompletedCheck
// Resolved stores successful resolution values keyed by (ResolverID, Key).
// This allows callers (e.g. AI AutoFix) to reuse resolved metadata even when
// handlers emit zero violations.
Resolved map[ResolutionKey]any
}
RunResult contains the output of an async runtime execution.
type Runtime ¶
type Runtime struct {
// Concurrency is the max number of concurrent resolver calls. Default 4.
Concurrency int
// Timeout is the global wall-clock budget for the async session.
Timeout time.Duration
// Resolvers provides resolver lookup for this runtime instance.
// When non-nil, used instead of the global resolver registry.
// This allows isolated resolver sets per invocation (useful for testing
// and for running multiple check sessions concurrently).
Resolvers map[string]Resolver
}
Runtime executes async check requests with concurrency limiting and timeouts.
type SkipReason ¶
type SkipReason string
SkipReason explains why an async check was not completed.
const ( SkipDisabled SkipReason = "disabled" SkipFailFast SkipReason = "fail-fast" SkipAuth SkipReason = "auth" SkipNotFound SkipReason = "not-found" SkipNetwork SkipReason = "network" SkipTimeout SkipReason = "timeout" SkipResolverErr SkipReason = "resolver-error" )
type Skipped ¶
type Skipped struct {
Request CheckRequest
Reason SkipReason
Err error
}
Skipped records a check that was planned but not completed.