I am wondering how to cancel an input read after a timer expires. I am currently reading from input with
fmt.Fscanln(reader, &var)
I have a channel that will be filled with a value as soon as the timer expires. I currently have the scan happening on a different go routine. This way, the function that scan's will return when it runs out of time.
The problem is if the io.Reader
passed to fmt.Fscanln
is reading from stdin
, it will still wait for input after its goroutine is over. Is there a way to cancel the read if time expires?
Thanks!