Skip to content

Commit

Permalink
don't call Publisher.register_on_subscription() when initially no sub…
Browse files Browse the repository at this point in the history
…scriber is available
  • Loading branch information
semiversus committed Dec 3, 2020
1 parent 155573b commit 9beb265
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 2 additions & 1 deletion broqer/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def register_on_subscription_callback(self,
raise ValueError('A callback is already registered')

self._on_subscription_cb = callback
callback(bool(self._subscriptions))
if self._subscriptions:
callback(True)

def __await__(self):
""" Makes publisher awaitable. When publisher has a state it will
Expand Down
4 changes: 0 additions & 4 deletions tests/test_core_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ def test_subscription_callback():
p = Publisher()
p.register_on_subscription_callback(m)

# callback should be immediatly called with `False` when no subscriber is available
m.assert_called_once_with(False)
m.reset_mock()

# callback should be called on first subscription (with True as argument)
d1 = p.subscribe(Sink())
m.assert_called_once_with(True)
Expand Down

0 comments on commit 9beb265

Please sign in to comment.