File tree Expand file tree Collapse file tree 5 files changed +47
-4
lines changed
Expand file tree Collapse file tree 5 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -557,6 +557,19 @@ Emit an event to a room.
557557Future which should be awaited. The result of the future will
558558be set to `None ` when successful.
559559
560+ # ## no_join
561+
562+ ```python
563+ Room().no_join(client: Client) -> None
564+ ```
565+
566+ Only translate the code _(or test the Id)_ to a room Id. This is useful if you only
567+ want to use the room to emit events and not listen to events.
568+
569+ # ### Args
570+ - client * (thingsdb.client.Client)* :
571+ ThingsDB client instance.
572+
560573
561574# # Failed packages
562575
Original file line number Diff line number Diff line change 11"""
2+ Local testing:
3+ pip install -e .
4+
25Upload to PyPI
36
47python3 setup.py sdist
Original file line number Diff line number Diff line change @@ -10,9 +10,9 @@ async def async_test_playground(self):
1010
1111 client = Client (ssl = True )
1212
13- # await client.connect('playground.thingsdb.net', 9400)
13+ await client .connect ('playground.thingsdb.net' , 9400 )
1414 try :
15- # await client.authenticate('Fai6NmH7QYxA6WLYPdtgcy')
15+ await client .authenticate ('Fai6NmH7QYxA6WLYPdtgcy' )
1616 data = await client .query (
1717 code = '.greetings[index];' ,
1818 index = 1 ,
@@ -28,4 +28,4 @@ def test_playground(self):
2828 loop .run_until_complete (self .async_test_playground ())
2929
3030
31- TestPlayground ().test_playground ()
31+ TestPlayground ().test_playground ()
Original file line number Diff line number Diff line change @@ -50,6 +50,33 @@ def scope(self):
5050 def client (self ):
5151 return self ._client
5252
53+ async def no_join (self , client : Client ):
54+ """Only translate the code to a room Id.
55+ This is useful if you wish to use the room for emitting events but
56+ not listening to events in this room.
57+ """
58+ async with client ._rooms_lock :
59+ if self ._scope is None :
60+ self ._scope = client .get_default_scope ()
61+ self ._client = client
62+
63+ if isinstance (self ._id , str ):
64+ code = self ._id
65+ id = await client .query (code , scope = self ._scope )
66+ if not isinstance (id , int ):
67+ raise TypeError (
68+ f'expecting ThingsDB code `{ code } ` to return with a '
69+ f'room Id (integer value), '
70+ f'but got type `{ type (id ).__name__ } `' )
71+ else :
72+ id = self ._id
73+ is_room = \
74+ await client .query (
75+ '!is_err(try(room(id)));' , id = id , scope = self ._scope )
76+ if not is_room :
77+ raise TypeError (f'Id `{ id } ` is not a room' )
78+ self ._id = id
79+
5380 async def join (self , client : Client , wait : Optional [float ] = 60.0 ):
5481 """Join a room.
5582
Original file line number Diff line number Diff line change 1- __version__ = '1.0.5-alpha1 '
1+ __version__ = '1.0.5-alpha2 '
You can’t perform that action at this time.
0 commit comments