Fixes the task.spawn, task.defer, and task.resume methods#874
Open
Vighnesh-V wants to merge 3 commits intoprimaryfrom
Open
Fixes the task.spawn, task.defer, and task.resume methods#874Vighnesh-V wants to merge 3 commits intoprimaryfrom
Vighnesh-V wants to merge 3 commits intoprimaryfrom
Conversation
8d3b645 to
c0f86cc
Compare
c0f86cc to
fb80b18
Compare
annieetang
reviewed
Mar 12, 2026
Contributor
annieetang
left a comment
There was a problem hiding this comment.
thx for fixing these!
baad122 to
20324c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #522
This PR refactors
task.spawn, defer, resumeto share most of their logic for creating the stack and handing control off to newly created threads. The cause of the bug in #522 was that the stack didn't get set up correctly in the parent stack due tolua_xmovepopping from the top, so the value that got returned was not callable withcoroutine.status(because it wasn't a thread). The code I've added documents the invariant that I wanted to maintain along with helpers for correctly setting up the stack.I've added tests for the following cases:
{task.defer, task.spawn, task.resume } called with { thread | function (except for task.resume, which only takes a thread passed { 0 arguments to resume with, > 0 arguments to resume with }.
I also introduced 'deferSelf' for the argumentless version of task.defer that says to immediately yield the current thread.