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

Adding threads to Trove can cause errors if thread is of running or normal status #74

Open
Sleitnick opened this issue Apr 27, 2022 · 0 comments

Comments

@Sleitnick
Copy link
Owner

Troves accept threads that will be closed when the trove is cleaned up. However, if this thread is the currently-running thread or marked as the "normal" thread, then it will throw an error. Here are a couple repros:

trove:Add(coroutine.running())
trove:Clean()
-- Error: cannot close running coroutine
trove:Add(coroutine.running())
task.spawn(function()
	trove:Clean()
end)
-- Error: cannot close normal coroutine

A thread that is in the "running" state means that it is the currently-active coroutine. A thread that is in the "normal" state means that it has resumed another coroutine and is awaiting that coroutine to yield back.

Thus, another example of the "normal coroutine" error would be such:

local thread1, thread2

thread1 = coroutine.create(function()
	trove:Clean()
end)

thread2 = coroutine.create(function()
	trove:Add(thread2)
	task.spawn(thread1)
end)

task.spawn(thread2)
-- Error: cannot close normal coroutine

And thus comes the question: How should Trove handle this? Should it just have better error messaging? Ideally, developers should only be placing threads into a Trove that they know will be fine to be closed. Simply checking the thread status on Add won't cut it, because that would assume that Clean would be called from the same thread that Add was called, which may not be the case.

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