Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Yield until graph object update

Open dphblox opened this issue 1 year ago • 2 comments

As part of the design of Eventuals (#4), Fusion is aiming to better support long-running imperative sequences embedded in a reactive system. As part of this, the process might wait for an object to change.

Right now, this would have to be implemented via polling:

scope:Eventual(function(use)
    repeat task.wait() until peek(state) == "foo"
end)

Ideally though, the change would be pushed to the imperative code:

scope:Eventual(function(use)
    repeat await(state) until peek(state) == "foo"
end)

Specific API surface TBD.

dphblox avatar Jul 15 '24 16:07 dphblox

Can the await function be called from anywhere? For example:

local eventual = Eventual(function(use)
 -- some processing that yields
end)

Computed(function(use)
 local value = await(eventual)
 -- is this allowed?
end)

If the above is allowed, then Computed states would essentially hold the same behavior as Eventuals in the sense they can be "pending". Might it be worth implementing yield support for Computed states generally? A side effect of this would be both peek and use potentially yielding if a Computed state is still "pending".

If the above is not allowed, would it make sense to throw an error claiming you cannot yield in the current context?

bytejon avatar Dec 05 '24 21:12 bytejon

Yielding rules in Computed likely wouldn't change here. It'll be the same as any other yielding code.

dphfox avatar Dec 09 '24 10:12 dphfox