Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Error when yielding in Computed/ComputedPairs

Open nottirb opened this issue 3 years ago • 7 comments

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

nottirb avatar Dec 18 '21 21:12 nottirb

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

nottirb avatar Dec 19 '21 17:12 nottirb

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

Dionysusnu avatar Jan 22 '22 06:01 Dionysusnu

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.

nottirb avatar Feb 07 '22 21:02 nottirb

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) )

ghost avatar Mar 02 '22 14:03 ghost

This is now being blocked by some design work being done in #4 - it may not be necessary if that goes through.

dphfox avatar Mar 24 '22 16:03 dphfox

It looks like that issue is not going to touch this area. Unblocked.

dphfox avatar Aug 23 '23 12:08 dphfox

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.

nottirb avatar Aug 31 '23 22:08 nottirb

Closing this PR due to a lack of motion.

dphfox avatar Apr 15 '24 12:04 dphfox