Created
May 22, 2020 12:21
-
-
Save RicardoLinck/51dbe5b11d4e9770d4535b441bf698ca 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
type data struct { | |
// ... | |
} | |
func main() { | |
c := make(chan data) | |
defer close(c) | |
go saveDataFromChannel(c) | |
wg := &sync.WaitGroup{} | |
wg.Add(1) | |
go getSampleData(c, wg) | |
wg.Add(1) | |
go getSampleData2(c, wg) | |
// ... | |
wg.Wait() | |
} | |
func getSampleData2(c chan data, wg *sync.WaitGroup) { | |
// ... | |
c <- data{} | |
wg.Done() | |
} | |
func getSampleData(c chan data, wg *sync.WaitGroup) { | |
// ... | |
c <- data{} | |
wg.Done() | |
} | |
func saveDataFromChannel(c chan data) { | |
for d := range c { | |
saveDataToMemCache(d) | |
} | |
} | |
func saveDataToMemCache(d data) { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment