Moved file reading to seperate func
This commit is contained in:
parent
b11c4701c3
commit
ad3d27157b
31
check.go
31
check.go
@ -70,24 +70,29 @@ func streams(files []string) chan input {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fileRead(j chan work, stream input) {
|
||||||
|
if stream.err != nil {
|
||||||
|
j <- work{err: stream.err}
|
||||||
|
//break
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s := bufio.NewScanner(stream.f)
|
||||||
|
for s.Scan() {
|
||||||
|
cs, err := parseCS(s.Text())
|
||||||
|
j <- work{cs, err}
|
||||||
|
}
|
||||||
|
stream.f.Close()
|
||||||
|
if s.Err() != nil {
|
||||||
|
j <- work{err: s.Err()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func check(files []string) chan error {
|
func check(files []string) chan error {
|
||||||
jobs := make(chan work)
|
jobs := make(chan work)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for stream := range streams(files) {
|
for stream := range streams(files) {
|
||||||
if stream.err != nil {
|
go fileRead(jobs, stream)
|
||||||
jobs <- work{err: stream.err}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
s := bufio.NewScanner(stream.f)
|
|
||||||
for s.Scan() {
|
|
||||||
cs, err := parseCS(s.Text())
|
|
||||||
jobs <- work{cs, err}
|
|
||||||
}
|
|
||||||
stream.f.Close()
|
|
||||||
if s.Err() != nil {
|
|
||||||
jobs <- work{err: s.Err()}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
close(jobs)
|
close(jobs)
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user