funx

package
v1.2.2 Latest Latest
Warning

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

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

Documentation

Overview

* @Author: cnzf1 * @Date: 2021-08-18 18:07:12 * @LastEditors: cnzf1 * @LastEditTime: 2023-03-27 13:43:26 * @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, opts ...DoOption) error

DoWithTimeout runs fn with timeout control.

Types

type DoConfig added in v1.2.1

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

type DoOption

type DoOption func(c *DoConfig)

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.

func WithStopChan added in v1.2.1

func WithStopChan(ch <-chan lang.PlaceholderType) DoOption

WithStopChan

func WithTimeout added in v1.2.1

func WithTimeout(tm time.Duration) DoOption

type RetryOption added in v1.1.9

type RetryOption func(*retryOptions)

RetryOption defines the method to customize DoWithRetry.

func WithPeriod added in v1.2.0

func WithPeriod(period time.Duration) RetryOption

WithPeriod customize a DoWithRetry call with given period(ms).

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