funx

package
v1.1.9 Latest Latest
Warning

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

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

Documentation

Overview

* @Author: cnzf1 * @Date: 2021-08-18 18:07:12 * @LastEditors: cnzf1 * @LastEditTime: 2023-01-11 13:46:55 * @Description: 控制超时时间运行函数

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCanceled is the error returned when the context is canceled.
	ErrCanceled = context.Canceled
	// ErrTimeout is the error returned when the context's deadline passes.
	ErrTimeout = context.DeadlineExceeded
)

Functions

func DoWithRetry added in v1.1.9

func DoWithRetry(fn func() error, opts ...RetryOption) error

DoWithRetry runs fn, and retries if failed. Default to retry 3 times.

func DoWithTimeout

func DoWithTimeout(fn func() error, timeout time.Duration, opts ...DoOption) error

DoWithTimeout runs fn with timeout control.

Types

type DoOption

type DoOption func() context.Context

DoOption defines the method to customize a DoWithTimeout call.

func WithContext

func WithContext(ctx context.Context) DoOption

WithContext customizes a DoWithTimeout call with given ctx.

type RetryOption added in v1.1.9

type RetryOption func(*retryOptions)

RetryOption defines the method to customize DoWithRetry.

func WithRetry added in v1.1.9

func WithRetry(times int) RetryOption

WithRetry customize a DoWithRetry call with given retry times.

Jump to

Keyboard shortcuts

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