mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-16 10:11:15 +00:00
first
This commit is contained in:
38
course/13-channels/exercises/3-channels_send/code.go
Normal file
38
course/13-channels/exercises/3-channels_send/code.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func waitForDbs(numDBs int, dbChan chan struct{}) {
|
||||
// ?
|
||||
}
|
||||
|
||||
// don't touch below this line
|
||||
|
||||
func test(numDBs int) {
|
||||
dbChan := getDatabasesChannel(numDBs)
|
||||
fmt.Printf("Waiting for %v databases...\n", numDBs)
|
||||
waitForDbs(numDBs, dbChan)
|
||||
time.Sleep(time.Millisecond * 10) // ensure the last print statement happens
|
||||
fmt.Println("All databases are online!")
|
||||
fmt.Println("=====================================")
|
||||
}
|
||||
|
||||
func main() {
|
||||
test(3)
|
||||
test(4)
|
||||
test(5)
|
||||
}
|
||||
|
||||
func getDatabasesChannel(numDBs int) chan struct{} {
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
for i := 0; i < numDBs; i++ {
|
||||
ch <- struct{}{}
|
||||
fmt.Printf("Database %v is online\n", i+1)
|
||||
}
|
||||
}()
|
||||
return ch
|
||||
}
|
||||
Reference in New Issue
Block a user