Skip to content

Commit

Permalink
pubsub secure start/stop
Browse files Browse the repository at this point in the history
  • Loading branch information
schroeder- committed Apr 27, 2022
1 parent 8c6f980 commit 6f97283
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions asyncua/pubsub/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(
self, cfg: PubSubConfigurationDataType = None, server: Server = None
) -> None:
super().__init__()
self._running = False
self._pds: List[PublishedDataSet] = []
self._con: List[PubSubConnection] = []
self._enabled = False
Expand Down Expand Up @@ -91,16 +92,22 @@ def remove_connection(self, name: String) -> None:
async def start(self) -> None:
'''
Starts the pubsub applications. All writer and reader will publish and subscripe message from now on.
'''
self._enabled = True
await asyncio.wait([asyncio.create_task(t.start()) for t in self._con])
"""
if not self._running:
self._enabled = True
await self._set_state(PubSubState.Operational)
await asyncio.wait([asyncio.create_task(t.start()) for t in self._con])
self._running = True

async def stop(self) -> None:
'''
Stops the pubsub application.
'''
self._enabled = False
await asyncio.wait([asyncio.create_task(t.stop()) for t in self._con])
"""
if self._running:
self._enabled = False
await self._set_state(PubSubState.Disabled)
await asyncio.wait([asyncio.create_task(t.stop()) for t in self._con])
self._running = False

async def __aenter__(self) -> None:
await self.start()
Expand Down

0 comments on commit 6f97283

Please sign in to comment.