timeout

package
v0.4.47 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package timeout provides support for contexts with extendable timeouts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler corresponds to a context created by the New function. It provides utility methods for extending the underlying context timeout during operations.

func New

func New(parent context.Context, d time.Duration) (context.Context, *Handler)

New returns a new context that is automatically cancelled after the given timeout duration. The timeout duration can be extended using the Reset and ResetFor methods on the returned Handler.

func (*Handler) Cancel

func (h *Handler) Cancel()

Cancel stops the underlying timer for the timeout, and cancels the associated context.

func (*Handler) Copy

func (h *Handler) Copy(dst io.Writer, src io.Reader, buf []byte, d time.Duration) (written int64, err error)

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

After each successful read, it keeps extending the timeout by the given duration d.

func (*Handler) ExpireAfter

func (h *Handler) ExpireAfter(d time.Duration)

ExpireAfter resets the context to timeout after duration d.

func (*Handler) ReadAll

func (h *Handler) ReadAll(r io.Reader, buf []byte, d time.Duration) ([]byte, error)

ReadAll reads from r until an error or EOF and returns the data it read. A successful call returns err == nil, not err == EOF. Because ReadAll is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

After each successful read, it keeps extending the timeout by the given duration d.

func (*Handler) Reset

func (h *Handler) Reset()

Reset resets the context timeout to the current moment.

Jump to

Keyboard shortcuts

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