Skip to content

Commit

Permalink
fix: Call listener when do_replay is True for use_table_listener_hook (
Browse files Browse the repository at this point in the history
…#313)

Fixes #290

Theoretically, there is some danger in this implementation, as if
dependencies change the listener will be called again, but I think it
makes more sense than just checking the first time, as the dependencies
changing means a completely different call. Maybe we need more danger
signs as has been alluded to. Maybe that's a docs issue.
  • Loading branch information
jnumainville authored Feb 23, 2024
1 parent 43ddf75 commit 86d2572
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/hooks/use_table_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def use_table_listener(
replay_lock: The lock type used during replay, default is ‘shared’, can also be ‘exclusive’.
"""

if not table.is_refreshing:
# if the table is not refreshing, there is nothing to listen to
if not table.is_refreshing and not do_replay:
# if the table is not refreshing, and is not replaying, there is nothing to listen to
return

def start_listener() -> Callable[[], None]:
Expand Down
29 changes: 28 additions & 1 deletion plugins/ui/test/deephaven/ui/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,27 @@ def _test_table_listener(replayed_table_val=table, listener_val=listener):
if not event.wait(timeout=LISTENER_TIMEOUT):
assert False, "listener was not called"

def verify_table_replayed(self, table):
from deephaven.ui.hooks import use_table_listener
from deephaven.table_listener import TableUpdate

event = threading.Event()

def listener(update: TableUpdate, is_replay: bool) -> None:
nonlocal event
event.set()

def _test_table_listener(replay_table=table, listener_val=listener):
use_table_listener(replay_table, listener_val, do_replay=True)

render_hook(_test_table_listener)

if not event.wait(timeout=LISTENER_TIMEOUT):
assert False, "listener was not called"

def test_table_listener(self):
from deephaven import DynamicTableWriter
from deephaven import DynamicTableWriter, new_table
from deephaven.column import int_col
import deephaven.dtypes as dht

column_definitions = {"Numbers": dht.int32, "Words": dht.string}
Expand All @@ -171,6 +190,14 @@ def test_table_listener(self):

self.verify_table_updated(table_writer, table, (1, "Testing"))

static_table = new_table(
[
int_col("Numbers", [1]),
]
)

self.verify_table_replayed(static_table)

def test_table_data(self):
from deephaven.ui.hooks import use_table_data
from deephaven import new_table
Expand Down

0 comments on commit 86d2572

Please sign in to comment.