Skip to content

Instantly share code, notes, and snippets.

@JeffBezanson
Created December 5, 2012 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffBezanson/4212658 to your computer and use it in GitHub Desktop.
Save JeffBezanson/4212658 to your computer and use it in GitHub Desktop.
add ProcessEachLine
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