Closed pysan3 closed 10 months ago
This would defeat the purpose of making it strict. I don't want these functions to work without being called within a task so I'll close this. I have however, exposed the current_task
function which you can use to make a small wrapper to expand as you want
local nio = require("nio")
local uv = setmetatable({}, {
__index = function(_, key)
if nio.current_task() then
return nio.uv[key]
end
return vim.loop[key]
end,
})
vim.print({ uv.fs_open("test.lua", "r", 438) })
Alright. That's a reasonable solution. Thanks a lot.
Btw don't forget to delete add("shutdown", 2)
that is defined twice.
After this commit, functions defined in
nio.uv
do not work when called outside of a task (async environment).Although I do agree with this design decision (which also matches the type annotations), I couldn't live without them being callable in sync from a practical standpoint.
With this PR, the function defined in
add
wraps the call totasks.wrap
and branches out to call sync version ofvim.loop
functions when not in a task, and manipulate the result to match that of wrapped calls (string?: err_msg, ...?: result
).If you @rcarriga don't agree with this approach, feel free to reject this PR tho.
I also added a few fixes.
strict = true
in nio.uv