Last active
September 2, 2022 15:18
-
-
Save abdulrahmanAlotaibi/5381690342930b8ac92cc233bd2fe0bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func addMsg(ch chan string, msg string){ | |
time.Sleep(10 * time.Second) | |
ch <- msg | |
} | |
func main() { | |
msgs := make(chan string) | |
go addMsg(msgs, "Abdulrahman") | |
select { | |
case msg := <- msgs : | |
fmt.Println("Recieved", msg) | |
case <- time.After(3 * time.Second): | |
fmt.Println("Timeout") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment