Fusion
Fusion copied to clipboard
Error when yielding in Computed/ComputedPairs
Implements #15, added a few unit tests to Computed.spec.lua specifically relating to yielding; not sure if I should also implement this into src/State/Observer?
Additional unit testing passes successfully: https://github.com/nottirb/Fusion/runs/4571365659?check_suite_focus=true
I pushed a fix for this change and updated the unit testing accordingly. You can see the new unit testing run here: https://github.com/nottirb/Fusion/actions/runs/1599013617
ComputedPairs is wrongly spelt as ComputerPairs in the test filename.
This implementation seems quite overcomplicated. A simple solution could be:
local returned = false
task.defer(function()
if not returned then
-- yielded, throw error
end
end)
local result = callback(...)
returned = true
return result
Worth mentioning that this has been deferred to v.0.3, and it remains to be seen whether or not we actually want this. Won't be making any updates to it until we have fully determined what we want.
ComputedPairs is wrongly spelt as ComputerPairs in the test filename.
This implementation seems quite overcomplicated. A simple solution could be:
local returned = false task.defer(function() if not returned then -- yielded, throw error end end) local result = callback(...) returned = true return result
This is a pretty satisfactory solution, however a better and ideal solution would be to call the callback in a new thread immediately via task.spawn, and then check the status of that thread via coroutine.status(resumedThread). If the thread (callback) did yield, close the thread via coroutine.close to effectively prevent it from running any further because it violated a rule (not to yield) and needs to be stopped.
local SUSPENDED_COROUTINE_STATUS = "suspended"
local function ResumeNoYield(callback, ...)
local thread = coroutine.create(callback)
task.spawn(thread, ...)
if coroutine.status(thread) == SUSPENDED_COROUTINE_STATUS then
coroutine.close(thread)
error("Cannot yield")
end
end
ResumeNoYield(function() task.wait() end) )
This is now being blocked by some design work being done in #4 - it may not be necessary if that goes through.
It looks like that issue is not going to touch this area. Unblocked.
I'll try and get to this at some point over the next few days, I just started college again and have some interviews scheduled so I'll fit it in whenever I get a chance!
If someone else wants to tackle it sooner just let me know and I'll close this PR.
Closing this PR due to a lack of motion.