package supervisor

Import Path
	go.pact.im/x/supervisor (on go.dev)

Dependency Relation
	imports 7 packages, and imported by 0 packages

Involved Source Files builder.go group.go interrupt.go Package supervisor provides [process.Runner] supervision implementation.
Code Examples { ctx := context.Background() builder := NewBuilder(GroupBuilder) _ = builder.Run(ctx, func(_ context.Context) error { g, _ := builder.Runner() g.Go(process.Nop(), nil) return nil }) }
Package-Level Type Names (total 6, in which 5 are exported)
/* sort exporteds by: | */
Type Parameters: T: process.Runner Builder is a reusable [process.Runner] implementation that uses [BuilderFunc] on each [Builder.Run] invocation to create a fresh [process.Runner] instance for implementations that would otherwise be single-use (do not allow calling Run more than once per instance). Run implements the [process.Runner] interface. It uses [BuildFunc] to create a runner, executes it, and discards the instance when complete. Use [Builder.Runner] to get the currently executing runner instance. Runner returns the runner currently executing via [Builder.Run] It returns false when no execution is active. *Builder : go.pact.im/x/process.Runner func NewBuilder[T](f BuilderFunc[T]) *Builder[T]
Type Parameters: T: process.Runner BuilderFunc is a factory function that constructs [process.Runner] instances. Run implements the [process.Runner] interface. It calls the factory function to create a runner, then delegates to that runner’s Run method. BuilderFunc : go.pact.im/x/process.Runner func Identity[T](runner T) BuilderFunc[T] func NewBuilder[T](f BuilderFunc[T]) *Builder[T]
Group manages a collection of [process.Runner] instances that run concurrently in the background and can be stopped together. Use Go method to add runners, Interrupt to signal them to shutdown gracefully, and Wait to wait for them to complete. Go starts a runner in the background, calling atExit when it finishes. Interrupt signals all runners started before the next [Group.Wait] call to stop. Run implements the [process.Runner] interface. It runs the callback, then interrupts all runners in the group and waits for them to complete. Wait blocks until all currently running processes exit. *Group : go.pact.im/x/process.Runner func GroupBuilder(ctx context.Context) (*Group, error) func NewGroup(ctx context.Context) *Group
Hook is a set of hooks for supervisor’s runner. Post is a function that is called before runner’s callback returns. The result is returned from the callback. Defaults to a function that returns nil error. Pre is a function that is called on runner’s callback. A non-nil error is immediately returned from the callback. In that case, an error from PostHook is ignored. Defaults to a function that returns nil error. func NewSupervisor(runner process.Runner, exec flaky.Executor, hook Hook) *Supervisor
Supervisor runs a [process.Runner] alongside a control callback, managing their concurrent execution and coordinated shutdown. It wraps the runner with [flaky.Executor] retry logic and pre/post execution hooks. Interrupt signals the supervisor to stop the current execution. This method is non-blocking and returns immediately; it does not wait for execution to complete. If no execution is active ([Supervisor.Run] is not being called), this method does nothing. Otherwise, it signals the process to stop, but the caller must separately wait for Run to return if synchronization is needed. It is safe to call from multiple goroutines concurrently. Run executes the supervisor’s managed process concurrently with the provided callback function without waiting for the initial process startup. Use [Hook.Pre] and [Hook.Post] to run code in runner’s callback. It returns an error combining any errors from the callback and runner execution. Execution timeline: - T0: Start runner under executor in background goroutine. - T0: Start callback in current goroutine. - T1: Callback returns → interrupt executor. - T1: Executor returns → cancel callback context. - T2: Wait for executor to complete cleanup → return combined errors. Only one active Run invocation is permitted per Supervisor instance. Concurrent or recursive calls will return an error. *Supervisor : go.pact.im/x/process.Runner func NewSupervisor(runner process.Runner, exec flaky.Executor, hook Hook) *Supervisor
Package-Level Functions (total 5, all are exported)
GroupBuilder is a [BuilderFunc] function for the [Group] type.
Type Parameters: T: process.Runner Identity returns a [BuilderFunc] that always returns the given runner.
Type Parameters: T: process.Runner NewBuilder returns a new [Builder] instance for the given factory function. The function will be called each time [Builder.Run] method is invoked to create a fresh runner instance.
NewGroup returns a new [Group] instance that runs processes in the background under the given context.
NewSupervisor returns a new [Supervisor] instance for the given runner.
Package-Level Variables (total 2, neither is exported)