Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Feb 4, 2025
1 parent 4fd8a5a commit 5ec5fa6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lua/fittencode/uv/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local Promise = require('fittencode.concurrency.promise')
-- 'fs_readdir', 'fs_closedir', 'fs_statfs'
-- }

---@class FittenCode.uv.fs
---@class FittenCode.UV.FS
---@field close function
---@field open function
---@field read function
Expand Down
6 changes: 3 additions & 3 deletions lua/fittencode/uv/init.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
--[[
-- 使用 Promise 链式调用
uv.fs.open('a.txt', 'r', 438)
:then(function(fd)
:forward(function(fd)
return uv.fs.read(fd, 1024, 0)
end)
:then(function(data)
:forward(function(data)
print('File content:', data)
end)
:catch(function(err)
Expand All @@ -16,7 +16,7 @@ local proc = uv.process.spawn('ls', {'-l'}, {
cwd = '/tmp'
})
proc._promise:then(function(result)
proc._promise:forward(function(result)
print('Exit code:', result.code)
print('Output:', result.stdout)
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/fittencode/uv/process2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc:wait()
local proc = uv_process.spawn('ls')
-- Promise 模式
proc:wait():then(print)
proc:wait():forward(print)
-- 流式操作
proc:pipe().stdout:read_start(function(_, data)
Expand Down
9 changes: 9 additions & 0 deletions lua/fittencode/uv/tempfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,13 @@ function M.create_temp_file(content)
end)
end

function M.with_temp_content_file(content, callback)
return M.with_temp_file(function(fd, path)
return fs.write(fd, content)
:forward(function()
return callback(path)
end)
end)
end

return M

0 comments on commit 5ec5fa6

Please sign in to comment.