Skip to content

Commit

Permalink
Tidy up new stream example
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Aug 31, 2012
1 parent b52c6fc commit 950c457
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/stream/modules/file.lua
Expand Up @@ -5,7 +5,7 @@ local iStream = require('stream').iStream

local fs = {}

fs.umask = tonumber("644", 8)
fs.umask = "0644"

local function noop() end

Expand All @@ -17,8 +17,8 @@ function fs.open(path, flag, mode)
error("open(path, flag, [mode]): flag must be a string")
end
if not mode then mode = fs.umask end
if type(mode) ~= "number" then
error("open(path, flag, [mode]): mode must be a number")
if type(mode) ~= "string" then
error("open(path, flag, [mode]): mode must be a string")
end
return function (callback)
return native.fsOpen(path, flag, mode, callback or noop)
Expand Down
9 changes: 5 additions & 4 deletions examples/stream/test.lua
Expand Up @@ -2,7 +2,8 @@ local fs = require('file')
local fiber = require('wait')

local input = __filename
local output = __filename .. ".out2"
local output = __filename .. ".out"
local output2 = __filename .. ".out2"

-- Create a normal continuable using callbacks
local normal = function (callback)
Expand Down Expand Up @@ -33,7 +34,7 @@ end
-- Create another that runs in a coroutine
local fibered = fiber.new(function (wait, await)
local readable = fs.ReadStream:new(await(fs.open(input, "r")))
local writable = fs.WriteStream:new(await(fs.open(output, "w")))
local writable = fs.WriteStream:new(await(fs.open(output2, "w")))
repeat
local chunk = await(readable:read())
await(writable:write(chunk))
Expand All @@ -43,10 +44,10 @@ end)

-- Run the normal one
normal(function (err, message)
p{name="normal", err=err,message=message}
p{name="normal", err=err, message=message}
end)

-- Also run the fibered one in parallel
fibered(function (err, message)
p{name="fibered", err=err,message=message}
p{name="fibered", err=err, message=message}
end)

0 comments on commit 950c457

Please sign in to comment.