Skip to content

Instantly share code, notes, and snippets.

@ronpastore
Created December 12, 2019 01:32
Show Gist options
  • Save ronpastore/472f254c8ff6e639c57b6254508803d4 to your computer and use it in GitHub Desktop.
Save ronpastore/472f254c8ff6e639c57b6254508803d4 to your computer and use it in GitHub Desktop.
package checker
import (
"github.com/davecgh/go-spew/spew"
"github.com/ronpastore/pricing/pkg/sources"
"github.com/ronpastore/pricing/pkg/core"
"sync"
)
func CheckAll() []core.PriceResult {
var waitGroup sync.WaitGroup
sources := []core.Source{
sources.DummySource{},
sources.AmazonSource{},
}
waitGroup.Add(len(sources))
resultChan := make(chan core.PriceResult, len(sources))
for _, entry := range sources {
go func(source core.Source) {
defer waitGroup.Done()
priceResult := source.Check()
resultChan <- priceResult
}(entry)
}
waitGroup.Wait()
close(resultChan)
results := toSlice(resultChan)
spew.Dump(results)
return results
}
func toSlice(c chan core.PriceResult) []core.PriceResult {
s := make([]core.PriceResult, 0)
for i := range c {
s = append(s, i)
}
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment