runtime

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package runtime provides utilities for deterministic process management and boilerplate reduction.

It focuses on:

  1. Preventing hangs during shutdown (timeouts).
  2. Standardizing application entry points (Run).
  3. Providing context-aware primitives (Sleep).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockWithTimeout

func BlockWithTimeout(done <-chan struct{}, timeout time.Duration) error

BlockWithTimeout blocks until the done channel is closed or the timeout expires. It returns nil if the operation completed (channel closed), or context.DeadlineExceeded if the timeout occurred.

Usage:

go func() {
    DoCleanup()
    close(done)
}()
if err := lifecycle.BlockWithTimeout(done, 5*time.Second); err != nil {
    // Force exit or log error
}

func Run added in v1.4.0

func Run(fn func(context.Context) error, opts ...signal.Option) error

Run executes the application logic with a managed SignalContext. It handles context creation, signal monitoring, and proper cleanup (Stop). It also ensures we Wait() for hooks if a signal triggered the shutdown. This is the recommended entry point for main().

func Sleep added in v1.4.0

func Sleep(ctx context.Context, d time.Duration) error

Sleep pauses the current goroutine for at least the duration d. Unlike time.Sleep, it returns immediately if the context is cancelled. Returns nil if the duration passed, or ctx.Err() if cancelled.

Types

This section is empty.

Jump to

Keyboard shortcuts

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