Skip to content

Instantly share code, notes, and snippets.

@creationix
Created September 4, 2014 22:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creationix/d7737e63fdfed84d1381 to your computer and use it in GitHub Desktop.
Save creationix/d7737e63fdfed84d1381 to your computer and use it in GitHub Desktop.
local coroutine = require('coroutine')
local table = require('table')
local uv = require("luv")
local function await(fn, ...)
local co = coroutine.running()
local args = {...}
table.insert(args, function (err, result)
if err then error(err) end
return assert(coroutine.resume(co, result))
end)
fn(unpack(args))
return coroutine.yield()
end
coroutine.wrap(function ()
local fd = await(uv.fs_open, uv.execpath(), "r", tonumber("644", 8))
local stat = await(uv.fs_fstat, fd)
local chunk = await(uv.fs_read, fd, 1000, stat.size-1000)
p{
fd=fd,
stat=stat,
chunk=chunk
}
end)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment