Created
December 5, 2012 05:38
-
-
Save JeffBezanson/4212658 to your computer and use it in GitHub Desktop.
add ProcessEachLine
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
diff --git a/base/process.jl b/base/process.jl | |
index e8fadae..74a8914 100644 | |
--- a/base/process.jl | |
+++ b/base/process.jl | |
@@ -677,11 +677,27 @@ end | |
readall(ports::Ports) = _readall(ports, cmds(ports)) | |
readall(cmds::Cmds) = _readall(stdout(cmds), cmds) | |
+type ProcessEachLine | |
+ stream::IO | |
+ c::Cmds | |
+end | |
+ | |
+start(itr::ProcessEachLine) = readline(itr.stream) | |
+function done(itr::ProcessEachLine, line) | |
+ if !isempty(line) | |
+ return false | |
+ end | |
+ wait(itr.c) | |
+ close(itr.stream) | |
+ true | |
+end | |
+next(itr::ProcessEachLine, this_line) = (this_line, readline(itr.stream)) | |
+ | |
function _each_line(ports::Ports, cmds::Cmds) | |
r = read_from(ports) | |
spawn(cmds) | |
fh = fdio(r.fd, true) | |
- EachLine(fh) | |
+ ProcessEachLine(fh, cmds) | |
end | |
each_line(ports::Ports) = _each_line(ports, cmds(ports)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment