Fusion
Fusion copied to clipboard
Yield until graph object update
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.
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?
Yielding rules in Computed likely wouldn't change here. It'll be the same as any other yielding code.