Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
lib: luvit: refactor the stdin pause logic
encapsulate all of the logic inside of createReadableStdioStream for
handling the unref'ing of the loop
  • Loading branch information
philips committed Jul 6, 2012
1 parent a54ef4c commit c005a34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/luvit/luvit.lua
Expand Up @@ -39,8 +39,6 @@ setmetatable(process, Emitter.meta)
-- Replace lua's stdio with luvit's
-- leave stderr using lua's blocking implementation
process.stdin = uv.createReadableStdioStream(0)
process.stdin:readStop()
native.unref()
process.stdout = uv.createWriteableStdioStream(1)
process.stderr = uv.createWriteableStdioStream(2)
Expand Down
17 changes: 11 additions & 6 deletions lib/luvit/uv.lua
Expand Up @@ -284,18 +284,23 @@ end

uv.createReadableStdioStream = function(fd)
local fd_type = native.handleType(fd);
local stdin
if (fd_type == "TTY") then
local tty = Tty:new(fd)
return tty
stdin = Tty:new(fd)
elseif (fd_type == "FILE") then
return fs.createReadStream(nil, {fd = fd})
stdin = fs.createReadStream(nil, {fd = fd})
elseif (fd_type == "NAMED_PIPE") then
local pipe = Pipe:new(nil)
pipe:open(fd)
return pipe
stdin = Pipe:new(nil)
stdin:open(fd)
else
error("Unknown stream file type " .. fd)
end

-- unref the event loop so that we don't block unless the user
-- wants stdin. This follows node's logic.
stdin:pause()

return stdin
end

function Process:initialize(command, args, options)
Expand Down

0 comments on commit c005a34

Please sign in to comment.