// Race runs all functions in parallel and returns the first that completes.
//
// Completion means a function either errors or succeeds.
// The result of the succeeded function is returned, the other results are
// discarded.
Race runs all functions in parallel and returns the first that completes.

Completion means a function either errors or succeeds.
The result of the succeeded function is returned, the other results are
discarded.
// Race runs all functions in parallel and returns the first that completes . // // Completion means a function either errors or succeeds . // The result of the succeeded function is returned the other results are // discarded .
func (f *Flow) Race(ctx context.Context, fns ...Func) error {
	if len(fns) == 0 {
		return nil
	}
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	results := make(chan error)
	f.runAll(len(fns), func(i int) {
		results <- fns[i](ctx)
	}, func() { close(results) })
	err := <-results
	cancel()
	for range results {
	}
	return err
}
func ( f * Flow ) Race ( ctx context . Context , fns ... Func ) error { if len ( fns ) == 0 { return nil } ctx , cancel := context . WithCancel ( ctx ) defer cancel ( ) results := make ( chan error ) f . runAll ( len ( fns ) , func ( i int ) { results <- fns [ i ] ( ctx ) } , func ( ) { close ( results ) } ) err := <- results cancel ( ) for range results { } return err }
Race runs all functions in parallel and returns the first that completes.
Race runs all functions in parallel and returns the first that completes .