Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion param/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2707,8 +2707,24 @@ def _upstream_awaiting(node):
last value, so readers must look past it to avoid computing with it.
Async refs are not considered: they write their value before they
settle, so the update that delivers the value would be skipped.
The walk stops at ``collect`` nodes, which report partial results
while their inputs are still pending.
"""
return any(n._awaiting for n in _unmirror(node)._upstream())
seen: set[int] = set()
stack = [_unmirror(node)]
while stack:
upstream = stack.pop()
if (id_node := id(upstream)) in seen:
continue
if upstream._awaiting:
return True
seen.add(id_node)
operation = upstream._operation
if operation is not None and operation['fn'] is _collect_marker:
continue
stack.extend(upstream._direct_inputs())
stack.extend(upstream._ref_inputs())
return False


def _settle_state(node):
Expand Down
22 changes: 22 additions & 0 deletions tests/testreactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6629,6 +6629,28 @@ async def delayed(v, delay):
)
assert not collected.rx.awaiting

async def test_reactive_collect_partial_results_reach_downstream_nodes_and_refs(self):
async def delayed(v, delay):
await asyncio.sleep(delay)
return v

class Members(param.Parameterized):
values = param.List(default=[], allow_refs=True)

a = rx(1).rx.pipe(delayed, delay=0.05)
b = rx(2).rx.pipe(delayed, delay=0.25)
listed = collect(a, b).args.rx.pipe(list)
members = Members(values=listed)

node_values, param_values = [], []
listed.rx.watch(node_values.append)
members.param.watch(lambda e: param_values.append(e.new), 'values')
listed.rx.value

expected = [[1, param.Undefined], [1, 2]]
await async_wait_until(lambda: node_values == expected[:1] and param_values == expected[:1], interval=10)
await async_wait_until(lambda: node_values == expected and param_values == expected, interval=10)

def test_reactive_collect_returns_a_namedtuple_of_args_and_kwargs(self):
a, b = rx(1), rx(2)
collected = collect(a, b, c=rx(3))
Expand Down
Loading