4
4
5
5
from channels .generic .websocket import AsyncJsonWebsocketConsumer
6
6
7
+ from idom .core .layout import Layout
7
8
from idom .core .dispatcher import dispatch_single_view
8
9
from idom .core .component import ComponentConstructor
9
10
@@ -18,17 +19,23 @@ def __init__(
18
19
super ().__init__ (* args , ** kwargs )
19
20
20
21
async def connect (self ) -> None :
22
+ await super ().connect ()
21
23
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
+ )
26
30
)
27
31
28
32
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 ()
30
37
await asyncio .wait ([self ._idom_dispatcher_future ])
31
- super ().close (* args , ** kwargs )
38
+ await super ().close (* args , ** kwargs )
32
39
33
40
async def receive_json (self , content : Any , ** kwargs : Any ) -> None :
34
41
await self ._idom_recv_queue .put (content )
0 commit comments