Skip to content

Commit debca80

Browse files
committed
add start and stop convenience methods to shared dispatcher
1 parent 46b05e2 commit debca80

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ or create a
2323
[pull request](https://github.com/rmorshea/idom/pulls). Thanks in advance!
2424

2525
<h3>
26-
<a href="https://mybinder.org/v2/gh/rmorshea/idom/master?filepath=notebooks%2Fintroduction.ipynb">
26+
<a
27+
target="_blank"
28+
href="https://mybinder.org/v2/gh/idom-team/idom-jupyter/master?filepath=notebooks%2Fintroduction.ipynb"
29+
>
2730
Try it Now
2831
<img alt="Binder" valign="bottom" height="25px"
2932
src="https://mybinder.org/badge_logo.svg"

idom/core/dispatcher.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ def __init__(self, layout: Layout) -> None:
9999
self._model_state: Any = {}
100100
self._update_queues: Dict[str, asyncio.Queue[LayoutUpdate]] = {}
101101

102+
async def start(self) -> None:
103+
await self.__aenter__()
104+
105+
async def stop(self):
106+
self.task_group.cancel_scope.cancel()
107+
await self.__aexit__(None, None, None)
108+
102109
@async_resource
103110
async def task_group(self) -> AsyncIterator[TaskGroup]:
104111
async with create_task_group() as group:

idom/server/sanic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ async def _activate_dispatcher(
167167
self, app: Sanic, loop: asyncio.AbstractEventLoop
168168
) -> None:
169169
self._dispatcher = cast(SharedViewDispatcher, self._make_dispatcher({}, loop))
170-
await self._dispatcher.__aenter__()
170+
await self._dispatcher.start()
171171

172172
async def _deactivate_dispatcher(
173173
self, app: Sanic, loop: asyncio.AbstractEventLoop
174174
) -> None: # pragma: no cover
175-
# this doesn't seem to get triffered during testing for some reason
176-
await self._dispatcher.__aexit__(None, None, None)
175+
# this doesn't seem to get triggered during testing for some reason
176+
await self._dispatcher.stop()
177177

178178
async def _run_dispatcher(
179179
self,

0 commit comments

Comments
 (0)