util/lineread: add docs to Reader

In particular, point out how to stop reading
and detect it on the other side.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
pull/950/head
Josh Bleecher Snyder 4 years ago committed by Josh Bleecher Snyder
parent 1ebbaaaebb
commit b65eee0745

@ -22,6 +22,11 @@ func File(name string, fn func(line []byte) error) error {
return Reader(f, fn) return Reader(f, fn)
} }
// Reader calls fn for each line.
// If fn returns an error, Reader stops reading and returns that error.
// Reader may also return errors encountered reading and parsing from r.
// To stop reading early, use a sentinel "stop" error value and ignore
// it when returned from Reader.
func Reader(r io.Reader, fn func(line []byte) error) error { func Reader(r io.Reader, fn func(line []byte) error) error {
bs := bufio.NewScanner(r) bs := bufio.NewScanner(r)
for bs.Scan() { for bs.Scan() {

Loading…
Cancel
Save