In this tutorial is following example provided:
func LongRunningHandler(ctx context.Context) string {
deadline, _ := ctx.Deadline()
for {
select {
case <- time.Until(deadline).Truncate(100 * time.Millisecond):
return "Finished before timing out."
default:
log.Print("hello!")
time.Sleep(50 * time.Millisecond)
}
}
}
When I compile this code I get following error: invalid operation: <-time.Until(deadline).Truncate(100 * time.Millisecond) (receive from non-chan type time.Duration)
What is wrong with the code from the example?