Cancelling input read from io.Reader After Time Limit

ⅰ亾dé卋堺 提交于 2020-04-12 05:12:25

问题


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!

来源:https://stackoverflow.com/questions/35537794/cancelling-input-read-from-io-reader-after-time-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!