golang-exercises/delayed-channel/main.go

33 lines
479 B
Go
Raw Permalink Normal View History

2024-03-08 11:26:58 +01:00
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)
}