You need to use multiple go routines and channels - one routine calls Scan() 
and when it gets the result it writes it to a channel, then the reader can 
timeout on the channel.

> On Dec 10, 2018, at 4:26 PM, Trig <edb1...@gmail.com> wrote:
> 
> I'm currently reading ASCII data from a serial port using the bufio.Scanner 
> (since what's coming back is a line at a time, it's convenient w/ reading 
> using the Scanner.Text()).  Problem is, the for loop I use to process the 
> reads lock at the Scanner.Scan() call.  Is there a to implement some for loop 
> that utilized the scanner while utilizing a timeout?
> 
> I've tried:
> 
> for {
>    select {
>       case <- time.After(time.Second * 3):
>          response <- &Response{
>             Error: fmt.Errorf("command call took to long for a response"),
>          }
> 
>          break
>       default:
>          myScanner.Scan()
> 
>          if myScanner.Text() == "OK" {
>             response <- &Response{
>                Content: []responseLines,
>             }
> 
>             break
>          }
>       
>          responseLines = append(responseLines, myScanner.Text())
>    }
> }
> 
> Of course, after looking at it... it makes sense why it's not working as the 
> loop locks at myScanner.Scan() if there is nothing further to Scan.  Any help 
> or examples would be appreciated.
> 
> -- 
> 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 
> <mailto:golang-nuts+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <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