Skip to content

Commit

Permalink
solve issue #16
Browse files Browse the repository at this point in the history
Make sure publish_lock is created on the right loop by creating it JIT
  • Loading branch information
orweis committed Apr 10, 2021
1 parent 6b80cdd commit 8e20606
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion fastapi_websocket_pubsub/event_broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, broadcast_url: str, notifier: EventNotifier, channel="EventNo
# The internal events notifier
self._notifier = notifier
self._is_publish_only = is_publish_only
self._publish_lock = asyncio.Lock()
self._publish_lock = None
# used to track creation / removal of resources needed per type (reader task->listen, and subscription to internal events->share)
self._listen_count: int = 0
self._share_count: int = 0
Expand All @@ -159,6 +159,10 @@ async def __broadcast_notifications__(self, subscription: Subscription, data):
await self._sharing_broadcast_channel.publish(self._channel, note.json())

def _acquire_sharing_broadcast_channel(self):
"""
Initialize the elements needed for sharing events with the broadcast channel
"""
self._publish_lock = asyncio.Lock()
self._sharing_broadcast_channel = self._broadcast_type(self._broadcast_url)

async def _subscribe_to_all_topics(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_requirements(env=""):

setup(
name='fastapi_websocket_pubsub',
version='0.1.17',
version='0.1.18',
author='Or Weis',
author_email="[email protected]",
description="A fast and durable PubSub channel over Websockets (using fastapi-websockets-rpc).",
Expand Down

0 comments on commit 8e20606

Please sign in to comment.