Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Example not working. nio.uv #2

Closed
pysan3 opened this issue Jan 12, 2024 · 7 comments
Closed

[BUG] Example not working. nio.uv #2

pysan3 opened this issue Jan 12, 2024 · 7 comments
Assignees

Comments

@pysan3
Copy link
Contributor

pysan3 commented Jan 12, 2024

NeoVim Version

NVIM v0.10.0-dev-2066+g1813661a6
Build type: RelWithDebInfo
LuaJIT 2.1.1703358377
Run "nvim -V1 -v" for more info

Describe the bug
Hi, thanks for an interesting plugin.

I think the following code in the README does not work.

If I understand correctly, the return value of nio.uv.fs_open is a single int (what should be file_fd), and does not return the error state.

To Reproduce

local file_path = "README.md"

local open_err, file_fd = nio.uv.fs_open(file_path, "r", 438)

vim.print(open_err) -- 52 (or any other int)
vim.print(file_fd)  -- nil

Am I understanding something wrong?

@rcarriga
Copy link
Contributor

This is because you haven't ran the code in nio.run. The wrap function (which is used for nio.uv) will run the wrapped function without a callback if not run from an async task (logic is here).

So what's actually happening is that vim.loop.fs_open is being called without a callback and so run synchronously.

@pysan3
Copy link
Contributor Author

pysan3 commented Jan 13, 2024

Ooh I see. That cleared up a lot of things. Thank you very much.

@pysan3 pysan3 closed this as completed Jan 13, 2024
@pysan3
Copy link
Contributor Author

pysan3 commented Jan 13, 2024

BTW, if that's the case, when it is not wrapped, the function type definitions do not match, right? @rcarriga

Does that mean that it is not intended to be run outside of a wrap function?
How about just raising an error, or at least printing a warning when not current_non_main_co()?

@rcarriga
Copy link
Contributor

The intention was to allow it to be flexible for using in async functions or outside but I think the default behaviour should raise an error, so I've allowed users to call it from a non-async context with an extra option

@pysan3
Copy link
Contributor Author

pysan3 commented Jan 16, 2024

This is a nice idea, and I love that it is true by default.

However, this fix will not solve the problem that the function annotations are not correct.
What if we always return a hardcoded nil, <result> when they are called in a non-async environment to make it align with the signatures?

I'd love to hear your opinion @rcarriga .

@pysan3 pysan3 reopened this Jan 17, 2024
@rcarriga
Copy link
Contributor

However, this fix will not solve the problem that the function annotations are not correct.

The function can no longer be called from a non-async context which means there's no way to get the previously incorrect return values and so the signature is correct, no?

@pysan3
Copy link
Contributor Author

pysan3 commented Jan 20, 2024

Oh that's right. Thanks.

@pysan3 pysan3 closed this as completed Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants