do

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

The deriveDo function executes a list of functions concurrently and returns their results.

Given the following input:

package do

func serviceCallOne() (string, error) {
	return "a", nil
}

func serviceCallTwo() (int, error) {
	return 1, nil
}

func serviceCalls() (string, int, error) {
	return deriveDo(serviceCallOne, serviceCallTwo)
}

goderive will generate the following code:

// Code generated by goderive DO NOT EDIT.

package do

// deriveDo concurrently executes the input functions f0 and f1 and when all functions are finished the first error, if any, and results are returned.
func deriveDo(f0 func() (string, error), f1 func() (int, error)) (string, int, error) {
	errChan := make(chan error)
	var v0 string
	go func() {
		var v0err error
		v0, v0err = f0()
		errChan <- v0err
	}()
	var v1 int
	go func() {
		var v1err error
		v1, v1err = f1()
		errChan <- v1err
	}()
	var err error
	for i := 0; i < 2; i++ {
		errc := <-errChan
		if errc != nil {
			if err == nil {
				err = errc
			}
		}
	}
	return v0, v1, err
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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