44
55from channels .generic .websocket import AsyncJsonWebsocketConsumer
66
7+ from idom .core .layout import Layout
78from idom .core .dispatcher import dispatch_single_view
89from idom .core .component import ComponentConstructor
910
@@ -18,17 +19,23 @@ def __init__(
1819 super ().__init__ (* args , ** kwargs )
1920
2021 async def connect (self ) -> None :
22+ await super ().connect ()
2123 self ._idom_recv_queue = recv_queue = asyncio .Queue ()
22- self ._idom_dispatcher_future = dispatch_single_view (
23- self ._idom_component_constructor ,
24- self .send_json ,
25- recv_queue .get ,
24+ self ._idom_dispatcher_future = asyncio .ensure_future (
25+ dispatch_single_view (
26+ Layout (self ._idom_component_constructor ()),
27+ self .send_json ,
28+ recv_queue .get ,
29+ )
2630 )
2731
2832 async def close (self , * args : Any , ** kwargs : Any ) -> None :
29- self ._idom_dispatcher_future .cancel ()
33+ if self ._idom_dispatcher_future .done ():
34+ await self ._idom_dispatcher_future
35+ else :
36+ self ._idom_dispatcher_future .cancel ()
3037 await asyncio .wait ([self ._idom_dispatcher_future ])
31- super ().close (* args , ** kwargs )
38+ await super ().close (* args , ** kwargs )
3239
3340 async def receive_json (self , content : Any , ** kwargs : Any ) -> None :
3441 await self ._idom_recv_queue .put (content )
0 commit comments