Documentation
¶
Overview ¶
Package run does something.
Example ¶
package main import ( "time" "github.com/superblocksteam/run" "github.com/superblocksteam/run/contrib/preempt" ) func main() { run.Add(true, preempt.New(100*time.Millisecond)) run.Run() }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ForwardCompatibility ¶
type ForwardCompatibility struct{}
ForwardCompatibility provides a mechanism that allows Runnables to always be forwards compatible with future version of the Runnable interface. The inspiration for this pattern comes from the Protobuf extension protoc-gen-grpc-go. We do not require it's embedding but it is highly recommended to ensure forwards compatibility.
func (ForwardCompatibility) Alive ¶
func (ForwardCompatibility) Alive() bool
func (ForwardCompatibility) Fields ¶
func (ForwardCompatibility) Fields() []slog.Attr
func (ForwardCompatibility) Name ¶
func (ForwardCompatibility) Name() string
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group manages a collection of Runnables.
func (*Group) Run ¶
Run invokes and manages all registered Runnables.
- Invoke Run on each Runnable concurrently.
- Wait for the first Runnable to return.
- Cancel the context passed to Run.
- Invoke Close on each Runnable concurrently.
- Wait for all Close methods to return.
- Wait for all Run methods to return.
It returns the initial error.
type Option ¶
type Option func(*Group)
func WithLogger ¶
WithLogger is a functional option for setting the logger.
type Runnable ¶
type Runnable interface { // Run is responsible for executing the main logic of the component // and is expected to run until it needs to shut down. Cancellation // of the provided context signals that the component should shut down // gracefully. If the Runnable implements the Close method than this // context can be ignored. // // Implementations must insure that instantiations of things to be // shutdown do not leak outside of this method (i.e. a constructor // calling net.Listen) as the Close method may not be called. Run(context.Context) error // Close is responsible for gracefully shutting down the component. It // can either initiate the shutdown process and return or wait for the // shutdown process to complete before returning. This method should // ensure that all resources used by the component are properly released // and any necessary cleanup is performed. If this method is not implemented // it is expected that the Run method properly handle context cancellation. Close(context.Context) error // Alive assesses whether the Runnable has // properly been initialized and is active. Alive() bool // Name returns the name of the Runnable. Name() string // Fields allows clients to attach additional fields // to every log message this library produces. Fields() []slog.Attr }
Click to show internal directories.
Click to hide internal directories.