Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
Collect takes error channels and returns a new error channel where all non-nil errors from input error channels are funneled into.
Example ¶
package main
import (
"fmt"
"net/http"
"github.com/sanggonlee/asyncutil"
)
func main() {
doWork := func(url string) chan error {
errs := make(chan error)
go func(url string) {
// Some expensive work..
_, err := http.Get(url)
if err != nil {
errs <- err
}
}(url)
return errs
}
for err := range asyncutil.Collect(
doWork("1"),
doWork("2"),
) {
if err != nil {
fmt.Println("Error:", err)
}
}
}
Output:
func CollectContext ¶
CollectContext is same as Collect, except it takes a context. If the context exceeds deadline or is cancelled, the resulting error channel receives the corresponding error, in addition to the errors collected by errchans. If the context was already cancelled by the time CollectContext is executed, the resulting error channel will only contain the context error, and not the errors collected by errchans.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.