Skip to content

Instantly share code, notes, and snippets.

@tsloughter
Created November 6, 2013 17:39
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 tsloughter/7340704 to your computer and use it in GitHub Desktop.
Save tsloughter/7340704 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
var i int
c := make(chan int)
fmt.Scan(&i)
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Printf("work failed: %v\n", err)
c <- -1
}
}()
fmt.Printf("i=%v\n", i)
x := 1 / i
fmt.Printf("x=%v\n", x)
c <- x
}()
select {
case m := <-c:
fmt.Printf("msg=%v\n", m)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment