thread

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	DefaultThreadErrorMaxRetries = 3
	DefaultThreadErrorRereyDelay = 300 * time.Millisecond
)

Variables

This section is empty.

Functions

func Retry

func Retry(config *RetryConfig, shouldRetry ShouldRetry, fn func() error) (err error)

Types

type Group

type Group struct {
	ResultC chan Result
	// contains filtered or unexported fields
}

A Group is reference to errgroup package

func NewGroup

func NewGroup() *Group

func (*Group) Go

func (g *Group) Go(job interface{}, fn func(job interface{}) error)

Go calls the given function in a new goroutine. It blocks until the new goroutine can be added without the number of active goroutines in the group exceeding the configured limit.

The first call to return a non-nil error cancels the group's context, if the group was created by calling WithContext. The error will be returned by Wait.

func (*Group) SetLimit

func (g *Group) SetLimit(n int)

SetLimit limits the number of active goroutines in this group to at most n. A negative value indicates no limit.

Any subsequent call to the Go method will block until it can add an active goroutine without exceeding the configured limit.

The limit must not be modified while any goroutines in the group are active.

func (*Group) Wait

func (g *Group) Wait()

Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.

type Result

type Result struct {
	Task     interface{}
	Duration string // unit: seconds
	Error    error
}

A Result is from the group

type RetryConfig

type RetryConfig struct {
	MaxRetries int           // Maximum number of retries
	Delay      time.Duration // The delay between each retry
}

type ShouldRetry

type ShouldRetry func(error) bool

ShouldRetry determines whether a retry is needed

shouldRetry := func(err error) bool {
	return errors.Is(err, ErrTemporaryFailure)
}

Jump to

Keyboard shortcuts

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