Skip to content

Commit

Permalink
fixing race
Browse files Browse the repository at this point in the history
  • Loading branch information
jnumainville committed Apr 19, 2024
1 parent 802361f commit 5bebb24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions plugins/ui/src/deephaven/ui/hooks/use_table_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ def use_table_data(
else:
executor_name = "concurrent"

table_updated = lambda: _set_new_data(table, sentinel, set_data, set_is_sentinel)
# memoize table_updated (and listener) so that they don't cause a start and stop of the listener
table_updated = ui.use_memo(
lambda: lambda: _set_new_data(table, sentinel, set_data, set_is_sentinel),
[table, sentinel],
)

# call table_updated in the case of new table or sentinel
ui.use_effect(table_updated, [table, sentinel])
listener = ui.use_memo(
lambda: partial(_on_update, ctx, table_updated, executor_name),
[table_updated, executor_name, ctx],
)

# call table_updated every time the table updates
ui.use_table_listener(
table, partial(_on_update, ctx, table_updated, executor_name), []
)
ui.use_table_listener(table, listener, [])

return transform(data, is_sentinel)
2 changes: 2 additions & 0 deletions plugins/ui/src/deephaven/ui/hooks/use_table_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def use_table_listener(
) -> None:
"""
Listen to a table and call a listener when the table updates.
If any dependencies change, the listener will be recreated.
In this case, updates may be missed if the table updates while the listener is being recreated.
Args:
table: The table to listen to.
Expand Down

0 comments on commit 5bebb24

Please sign in to comment.