Skip to content

Instantly share code, notes, and snippets.

@cablehead
Created November 22, 2016 23:56
Show Gist options
  • Save cablehead/5c07414b6cd3b13777d7e17fa7ff09a6 to your computer and use it in GitHub Desktop.
Save cablehead/5c07414b6cd3b13777d7e17fa7ff09a6 to your computer and use it in GitHub Desktop.
local levee = require("levee")
local _ = levee._
local h = levee.Hub()
_.fcntl_nonblock(0); h.stdin = h.io:r(0)
_.fcntl_nonblock(1); h.stdout = h.io:w(1)
local stream = h.stdin:stream()
local count= 0
while true do
local err, line = stream:line()
if err then break end
h.stdout:send(line, "\n")
count = count + 1
end
h.stdout:send(("count: %s\n"):format(count))
h.stdout.empty:recv()
imgix:tmp andy$ for i in $(seq 1 3) ; do echo $i; sleep 1; done | levee run io.lua
1
2
3
count: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment