Created
September 4, 2014 22:43
-
-
Save creationix/d7737e63fdfed84d1381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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