Added delayed-channel exercise

This commit is contained in:
Raul 2024-03-08 10:26:58 +00:00
parent 1279df8aab
commit 569b255bfa
2 changed files with 35 additions and 0 deletions

3
delayed-channel/go.mod Normal file
View File

@ -0,0 +1,3 @@
module delayed-channel
go 1.22.1

32
delayed-channel/main.go Normal file
View File

@ -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)
}