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 ¶
DoWithTimeout runs fn with timeout control.
Types ¶
type DoOption ¶
type DoOption func(c *DoConfig)
DoOption defines the method to customize a DoWithTimeout call.
func WithContext ¶
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
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.
Click to show internal directories.
Click to hide internal directories.