Files
bootdotdev-fcc-learn-golang…/course/13-channels/exercises/4-buffered_channels/complete.go
wagslane 9be3074de6 first
2023-05-01 15:25:27 -06:00

35 lines
913 B
Go

package main
import "fmt"
func addEmailsToQueue(emails []string) chan string {
emailsToSend := make(chan string, len(emails))
for _, email := range emails {
emailsToSend <- email
}
return emailsToSend
}
// TEST SUITE - Don't Touch Below This Line
func sendEmails(batchSize int, ch chan string) {
for i := 0; i < batchSize; i++ {
email := <-ch
fmt.Println("Sending email:", email)
}
}
func test(emails ...string) {
fmt.Printf("Adding %v emails to queue...\n", len(emails))
ch := addEmailsToQueue(emails)
fmt.Println("Sending emails...")
sendEmails(len(emails), ch)
fmt.Println("==========================================")
}
func main() {
test("Hello John, tell Kathy I said hi", "Whazzup bruther")
test("I find that hard to believe.", "When? I don't know if I can", "What time are you thinking?")
test("She says hi!", "Yeah its tomorrow. So we're good.", "Cool see you then!", "Bye!")
}