-racepprof outputfunc main() {
ch := make(chan obj)
go func() {
// some long non blocking work...
ch <- something
}()
select{
case rslt := <-ch:
fmt.Println(rslt)
case <-time.After(timeout):
fmt.Println("Timed out")
}
}
Mutex, WaitGroup or selectAdd() to a waitgroup before starting the unit of work that calls Done(), otherwise wg.Wait() could return prematurelydefer)