Created
November 29, 2020 10:12
-
-
Save RicardoLinck/defa0ab7bd5256b120d5e0a74af9b176 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"time" | |
"github.com/RicardoLinck/scatter-gather/fetch" | |
"github.com/RicardoLinck/scatter-gather/nameservice" | |
"golang.org/x/sync/errgroup" | |
) | |
func main() { | |
go nameservice.StartServer() | |
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500) | |
defer cancel() | |
g, ctx := errgroup.WithContext(ctx) | |
fs := configureFetchers(ctx) | |
results := make(chan fetch.Result, len(fs)) | |
for _, f := range fs { | |
f := f | |
g.Go(func() error { return f.Fetch(ctx, "[email protected]", results) }) | |
} | |
err := g.Wait() | |
close(results) | |
for result := range results { | |
r := result | |
fmt.Println(r) | |
} | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
func configureFetchers(ctx context.Context) []fetch.Fetcher { | |
return []fetch.Fetcher{ | |
fetch.NewCancellationFetcher(fetch.NewNameFetcher("http://localhost:8787")), | |
fetch.NewCancellationFetcher(fetch.NewPartnerFetcher()), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment