Scan() returns false when it reaches EOF or an error, so with what you
provided i assume you're missing to check that.
for ns.Scan() {
...
}

or

for {
if !ns.Scan() {
    break
}

-wgr

On Sun, Dec 30, 2018 at 10:36 PM Trig <edb1...@gmail.com> wrote:
>
> I'm currently utilizing the bufio.NewScanner to read ASCII data from a serial 
> port.  I have the following simple code:
>
> ns := bufio.NewScanner(sPort)
>
> for {
>    ns.Scan()
>    if ns.Text() != "" { // ignore blank lines
>       // handle content here
>    }
> }
>
> The problem is ns.Scan() blocks the loop from continuing if there isn't any 
> data.  This leaves me unable to break out of the loop with a for condition or 
> a select statement also within the loop which is looking for a close command 
> from a channel before or after it, etc.  Am I doing something wrong, or is 
> there a proper way to handle this?
>
> --
> 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