limit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package limit provides means to limit the duration of functions It is meant to complement samber/lo utilities like Attempt and WaitFor .

Functions in this package pair well with lang.ReaderContains or regexp.MatchReader which are not context-aware and can take a long time, especially on slow or unbounded readers like process pipes or network streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTimeout

func WithTimeout[T any](d time.Duration, f func() T) (result T, ok bool)

WithTimeout attempts to run the given context-unaware function within the given timeout duration. Use WithinCtx directly if there is parent context or the function is context-aware.

func WithinCtx

func WithinCtx[T any](ctx context.Context, f func(context.Context) T) (result T, ok bool)

WithinCtx attempts to run the given function until the context expires. The function itself can, optionally, limit its own execution on the same context. Returns the result of the function and whether the function completed while the context was valid. Functions with multiple return values can use samber/lo Tuples to pack them.

This utility can turn a function which is not context-aware, or only partially so, into a strictly context-aware one. Additionally, in combination with context.WithDeadline, it can put time limits on execution attempts.

Types

This section is empty.

Jump to

Keyboard shortcuts

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