On 2 September 2016 at 06:21, mhhcbon <cpasmaboiteas...@gmail.com> wrote:

> I dig into the repo you mentioned, TBHonnest, im not that wise, and it
> remains unclear.
> For the few i know, select is the approach to take, but the API is unclear.
>
> Not sure if it s possible to come up with something as straight as
> `NewReader(os.Stdin).Block(false).Read()`
>

As I said, the select system call is a pain to use in Go---not least
because the macros FD_SET et al seem to be missing.
But it is possible: https://play.golang.org/p/GhdrMkiElc.

Another approach is to make the stdin file descriptor non-blocking, so that
attempting to read from it will fail immediately if there is no data
available.
See: https://play.golang.org/p/yHrDdzWoDk

Admittedly, neither of these approaches is straightforward.  A more typical
Go approach is to start the read in its own goroutine and let it run to
completion, even if no data ever arrives.  Of course, while simple to
program, this is not ideal if you need to cancel the read after the timeout
has expired.

-- 
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