Replies: 3 comments 3 replies
-
I think your suggestion will break the await-in-sync diagnostic checking logic. 😕
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"diagnostics.groupFileStatus": {
"await": "Any"
}
}
---@async
local function async() end
local function dont_want_async()
async() --> warning: Async function can only be called in async function.Lua Diagnostics.(await-in-sync)
end If |
Beta Was this translation helpful? Give feedback.
-
I know it's not polite to @sumneko, but do you have any solution to this problem? Thank you very much。 |
Beta Was this translation helpful? Give feedback.
-
我觉得手动标记所有的异步比较好,异步是非常复杂的,在逐一标记的过程中会强迫你思考调用链上的每个函数是否会有重入问题,是否会阻塞不该阻塞的流程,回调函数是否会经过不支持让出的栈帧。 我目前也没有精力修改这方面的实现,如果你有强烈需求的话可以提PR。 |
Beta Was this translation helpful? Give feedback.
-
Background
In Lua, asynchronous operations are often handled via coroutines (e.g., using coroutine.yield). When one function calls another asynchronous function that uses coroutine, the calling function is inherently asynchronous as well, because the execution of the calling function is paused and resumed once the asynchronous operation completes.
However, currently, the @async annotation does not propagate upwards. This means that if a function calls an asynchronous function (e.g., using coroutine.yield or returning a Promise), the calling function needs to be manually marked as @async in order to ensure that the asynchronous nature is captured correctly. It would be great if this could be automated.
Proposal
If a function calls another function that is marked as @async and uses coroutines (or similar async patterns), the calling function should automatically inherit the @async annotation, similar to how asynchronous behavior is propagated in many other languages (e.g., TypeScript).
This would reduce the need for redundant annotations and help maintain consistency in larger codebases where multiple functions are asynchronous and rely on coroutines for concurrency.
Benefits
Consistency: Functions that use async functions (e.g., fetchData) should automatically inherit the @async annotation to prevent forgetting to annotate dependent functions.
Reduced Boilerplate: This feature would reduce the need for redundant annotations, especially in large codebases with many interdependent asynchronous functions.
Improved Developer Experience: Automatic propagation would improve the development workflow, ensuring that async functions are correctly marked without manual intervention.
Beta Was this translation helpful? Give feedback.
All reactions