-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* impl worker * worker method * update
- Loading branch information
Showing
10 changed files
with
242 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package gtree | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"io" | ||
"strings" | ||
) | ||
|
||
func split(ctx context.Context, r io.Reader) (<-chan string, <-chan error) { | ||
sc := bufio.NewScanner(r) | ||
strc := make(chan string) | ||
errc := make(chan error) | ||
|
||
go func() { | ||
defer func() { | ||
close(strc) | ||
close(errc) | ||
}() | ||
|
||
ret := "" | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
default: | ||
for sc.Scan() { | ||
l := sc.Text() | ||
if strings.HasPrefix(l, "-") { | ||
if !(len(ret) == 0) { | ||
strc <- ret | ||
} | ||
|
||
ret = "" | ||
ret += fmt.Sprintln(l) | ||
continue | ||
} | ||
ret += fmt.Sprintln(l) | ||
} | ||
|
||
strc <- ret // 最後のRoot送出 | ||
errc <- sc.Err() | ||
return | ||
} | ||
} | ||
}() | ||
|
||
return strc, errc | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.