-
Notifications
You must be signed in to change notification settings - Fork 72
RFC: function coroutine.noyield(fn, ...)
#140
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
base: master
Are you sure you want to change the base?
RFC: function coroutine.noyield(fn, ...)
#140
Conversation
coroutine noyield(fn, ...)coroutine.noyield(fn, ...)
|
Shouldn't it return a success boolean like pcall? and I think |
This isn't a protected call - it's a call that is not allowed to yield. Yielding from the called function causes an error. It means the called function can handle this error, if it doesn't, it gets propagated. Users who want to detect errors in the called function, including an unexpected yield, should wrap the call in I don't believe there's much of a use case for
A status boolean indicating if the function requested to yield would also introduce an extra return - for information that is probably not useful. If we use I can't really think of a use for
If what you want is to enforce that a function does not cause a yield: coroutine.noyield(myFunc)If what you want is to enforce that a function does not cause a yield, and handle an error (including yields): local ok, ret = pcall(coroutine.noyield, myFunc)
if not ok then
-- Error recovery here
else
-- Proceed
endIf what you want is to detect yielding and give it a special treatment: local coro = coroutine.create(myFunc)
local ok, ret = coroutine.resume(myFunc)
if coroutine.status(coro) ~= "dead" then
-- Yield handling here
else
-- Proceed
end
Sounds consistent, but this doesn't address one of the motivations behind |
|
The proposal isn't to reintroduce Lua's old |
|
I don't think we will be accepting this proposal, it requires too many changes to the VM for only a limited utility (given that there are multiple available workarounds).
That solution will actually not require any changes to the VM compared to your proposal so in a way will be preferrable. VM changes which will block this PR from being accepted:
RFC might get a chance if it drops these extra requirements. int noyield(lua_State* L)
{
luaL_checkany(L, 1);
return lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
}RFC can also use some trimming. For transparency, I would also like for you to confirm that AI was not used to generate this RFC. |
I've been taking a look around in the VM since I made the PR, and have found that the proposed design is rather complex to implement. Specifically, the special C stack detail adds considerable complexity to Luau. If users need to avoid the C stack limit, they can just do if coroutine.isyieldable() then
return coroutine.noyield(fn, ...)
else
return fn(...)
end
The idea is to have calls that are only stopped by About the size of the RFC, it's pretty big, yeah. I was a bit bored and figured I would include little experiments in collapsible sections. AI wasn't used, I'm not a native English speaker, so I might just sound a little robotic trying to speak formally. Some of the wording is a bit repetitive, I wasn't satisfied with how shorter more concise iterations of the text got the point across. I'll clean up details and review the proposal. |
|
Another consideration: yielding from Luau's C API is a "fire-and-forget" operation, so any resumption logic has to be set up before the yield is signaled. For example, a minimal implementation of Under this proposal, we reject the yield by raising an error, but there's no way to prevent the scheduled thread resumption since it was set up before the yield was signaled. Yielding in the Luau C API isn't a handshake; there's no way for the caller to "veto" it after the fact, and supporting that would require other changes to the API. When |
|
@vrn-sn This is true, but unimportant because this is already how these mechanisms work today when attempting to yield in non-yieldable contexts. |
|
If I recall, we really want the VM to support yielding everywhere, don't we? |
|
I don't know if that's a goal or not, but I do know that it cannot happen because of performance constraints. |
Rendered
This proposal creates a new standard library function in
coroutine:It runs a function within the same thread as the caller, without allowing it to yield, reflecting it in
coroutine.isyieldable()and causingcoroutine.yield()to error.