Added delayed-channel exercise
This commit is contained in:
parent
1279df8aab
commit
569b255bfa
|
@ -0,0 +1,3 @@
|
|||
module delayed-channel
|
||||
|
||||
go 1.22.1
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func delayerSum(c chan int) {
|
||||
val := 0
|
||||
for i := 0; i < 10; i++ {
|
||||
val = val + 1
|
||||
}
|
||||
time.Sleep(time.Second * 5)
|
||||
c <- val
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Starting the delayed function, please wait")
|
||||
loading := "Loading."
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
fmt.Printf("\r%v", loading)
|
||||
loading = loading + "."
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
delSum := make(chan int)
|
||||
go delayerSum(delSum)
|
||||
|
||||
finalValue := <-delSum
|
||||
fmt.Println(finalValue)
|
||||
}
|
Loading…
Reference in New Issue