Skip to content

Instantly share code, notes, and snippets.

@abdulrahmanAlotaibi
Last active September 2, 2022 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulrahmanAlotaibi/5381690342930b8ac92cc233bd2fe0bd to your computer and use it in GitHub Desktop.
Save abdulrahmanAlotaibi/5381690342930b8ac92cc233bd2fe0bd to your computer and use it in GitHub Desktop.
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