File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,14 @@ async def example():
4747 await lego .load (client )
4848
4949 # ... now the collection will be watched for 100 seconds
50+ while True :
51+ await asyncio .sleep (3 )
52+ if lego and lego .bricks :
53+ brick = lego .bricks [0 ]
54+ await brick .emit ('new-color' , 'RED' )
55+ break
56+ await lego .query ('.bricks.push(Brick{});' )
57+
5058 await asyncio .sleep (300 )
5159
5260 finally :
Original file line number Diff line number Diff line change @@ -94,6 +94,16 @@ def unwatch(self):
9494 collection = self ._collection
9595 return collection ._client .unwatch (self ._id , scope = collection ._scope )
9696
97+ def emit (self , event , * args ):
98+ data = {f'd{ i } ' : v for i , v in enumerate (args )}
99+ dstr = "" .join ((f", { k } " for k in data .keys ()))
100+
101+ return self ._collection .query (
102+ f'thing(id).emit(event{ dstr } );' ,
103+ id = self ._id ,
104+ event = event ,
105+ ** data )
106+
97107 @checkevent
98108 def on_init (self , event , data ):
99109 self ._job_set (data )
You can’t perform that action at this time.
0 commit comments