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

Unintentionally global variables stat and ret in async_lib? #582

Open
bluss opened this issue May 12, 2024 · 0 comments
Open

Unintentionally global variables stat and ret in async_lib? #582

bluss opened this issue May 12, 2024 · 0 comments

Comments

@bluss
Copy link

bluss commented May 12, 2024

It looks like stat and ret should be local in this code and not global.

This is a common mistake in lua that happens easily I guess. Found by lua language server autocomplete.

To make them local would make them encapsulated, and you avoid risk - people using the unintentionally used variables, or overwriting people's globals.

Link:

M.protected = async(function(future)
local tx, rx = M.channel.oneshot()
stat, ret = pcall(future, tx)
if stat == true then
return stat, await(rx())
else
return stat, ret
end
end)

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

1 participant