File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 88 KeysView ,
99 Sequence ,
1010)
11+ from contextlib import AbstractAsyncContextManager
1112from types import (
1213 TracebackType ,
1314)
@@ -1178,7 +1179,9 @@ def get_live_peers(self) -> list[ID]:
11781179 """
11791180
11801181 @abstractmethod
1181- def run (self , listen_addrs : Sequence [Multiaddr ]) -> AsyncContextManager [None ]:
1182+ def run (
1183+ self , listen_addrs : Sequence [Multiaddr ]
1184+ ) -> AbstractAsyncContextManager [None ]:
11821185 """
11831186 Run the host and start listening on the specified multiaddresses.
11841187
Original file line number Diff line number Diff line change 33 Sequence ,
44)
55from contextlib import (
6+ AbstractAsyncContextManager ,
67 asynccontextmanager ,
78)
89import logging
@@ -147,19 +148,23 @@ def get_connected_peers(self) -> list[ID]:
147148 """
148149 return list (self ._network .connections .keys ())
149150
150- @asynccontextmanager
151- async def run (
151+ def run (
152152 self , listen_addrs : Sequence [multiaddr .Multiaddr ]
153- ) -> AsyncIterator [None ]:
153+ ) -> AbstractAsyncContextManager [None ]:
154154 """
155155 Run the host instance and listen to ``listen_addrs``.
156156
157157 :param listen_addrs: a sequence of multiaddrs that we want to listen to
158158 """
159- network = self .get_network ()
160- async with background_trio_service (network ):
161- await network .listen (* listen_addrs )
162- yield
159+
160+ @asynccontextmanager
161+ async def _run () -> AsyncIterator [None ]:
162+ network = self .get_network ()
163+ async with background_trio_service (network ):
164+ await network .listen (* listen_addrs )
165+ yield
166+
167+ return _run ()
163168
164169 def set_stream_handler (
165170 self , protocol_id : TProtocol , stream_handler : StreamHandlerFn
You can’t perform that action at this time.
0 commit comments