Skip to content

Commit 56b12c5

Browse files
committed
Add adapter setting behaviour and expose adapter property.
1 parent 0740977 commit 56b12c5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

twitchio/client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,33 @@ def __init__(
166166

167167
self.__waiter: asyncio.Event = asyncio.Event()
168168

169+
@property
170+
def adapter(self) -> BaseAdapter:
171+
"""Property returning the :class:`~twitchio.AiohttpAdapter` or :class:`~twitchio.StarlettepAdapter` the bot is
172+
currently running."""
173+
return self._adapter
174+
175+
async def set_adapter(self, adapter: BaseAdapter) -> None:
176+
"""|async|
177+
178+
Method which sets and starts a new web adapter which inherits from either :class:`~twitchio.AiohttpAdapter` or
179+
:class:`~twitchio.StarlettepAdapter` or implements the :class:`~twitchio.BaseAdapter` specifications.
180+
181+
Parameters
182+
----------
183+
adapter: :class:`~twitchio.BaseAdapter`
184+
The new adapter to assign and start.
185+
186+
Returns
187+
-------
188+
None
189+
"""
190+
if self._adapter:
191+
await self._adapter.close()
192+
193+
self._adapter = adapter
194+
await self._adapter.run()
195+
169196
@property
170197
def tokens(self) -> MappingProxyType[str, TokenMappingData]:
171198
"""Property which returns a read-only mapping of the tokens that are managed by the `Client`.

0 commit comments

Comments
 (0)