If it helps, you can set deadlines on *os.File now, as of Go 1.10:

   https://play.golang.org/p/h3Pg9Ql0CMB

I don't see a way to cancel without deciding the deadline in advance though.

On 15 March 2018 at 08:40, Matt Mueller <mattmue...@gmail.com> wrote:
> Hey folks,
>
> I'm trying to figure out how to cancel reading from stdin programmatically.
> Basically the same way that ctrl+d works on OSX.
>
> I would have thought this would work, but this program will just run
> forever:
>
> package main
>
>
> import (
>  "io/ioutil"
>  "os"
>  "time"
> )
>
>
> func main() {
>  go func() {
>  time.Sleep(time.Second)
>  println("closing...")
>  os.Stdin.Close()
>  }()
>
>  _, _ = ioutil.ReadAll(os.Stdin)
>  println("done")
> }
>
>
> Any help would be much appreciated – thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to