concurrent

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 3 Imported by: 0

README

Usage

Runner executes the provided functions in concurrent and collects any errors they return.

Example

package main 

import (
	"github.com/donutloop/toolkit/concurrent"
	"log"
)

func main() {
	concurrent.Run(
		func() error {
	        // do things
		},
		func() error {
			// do things
			return nil
		},
	)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(fns ...func() error) []error

Run executes the provided functions in concurrent and collects any errors they return. Be careful about your resource consumption.

Example

Run concurrently your func() error.

package main

import (
	"fmt"
	"sync/atomic"

	"github.com/donutloop/toolkit/concurrent"
)

func main() {
	counter := int32(0)
	errs := concurrent.Run(
		func() error {
			atomic.AddInt32(&counter, 40)
			return nil
		},
		func() error {
			atomic.AddInt32(&counter, 2)
			return nil
		},
	)

	if len(errs) > 0 {
		for _, err := range errs {
			fmt.Printf("error: %v \n", err)
		}
	}

	fmt.Println(counter)
}
Output:

42

Types

type RecoverError

type RecoverError struct {
	Err   interface{}
	Stack []byte
}

func (*RecoverError) Error

func (e *RecoverError) Error() string

Jump to

Keyboard shortcuts

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