mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Add sequential parameter to compose()
This commit is contained in:
parent
5681ccefe1
commit
f6283757e1
@ -16,13 +16,17 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from .idle import idle
|
from .idle import idle
|
||||||
|
|
||||||
|
|
||||||
async def compose(clients: List["pyrogram.Client"]):
|
async def compose(
|
||||||
|
clients: List["pyrogram.Client"],
|
||||||
|
sequential: bool = False
|
||||||
|
):
|
||||||
"""Run multiple clients at once.
|
"""Run multiple clients at once.
|
||||||
|
|
||||||
This method can be used to run multiple clients at once and can be found directly in the ``pyrogram`` package.
|
This method can be used to run multiple clients at once and can be found directly in the ``pyrogram`` package.
|
||||||
@ -33,6 +37,10 @@ async def compose(clients: List["pyrogram.Client"]):
|
|||||||
clients (List of :obj:`~pyrogram.Client`):
|
clients (List of :obj:`~pyrogram.Client`):
|
||||||
A list of client objects to run.
|
A list of client objects to run.
|
||||||
|
|
||||||
|
sequential (``bool``, *optional*):
|
||||||
|
Pass True to run clients sequentially.
|
||||||
|
Defaults to False (run clients concurrently)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@ -53,10 +61,16 @@ async def compose(clients: List["pyrogram.Client"]):
|
|||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for c in clients:
|
if sequential:
|
||||||
await c.start()
|
for c in clients:
|
||||||
|
await c.start()
|
||||||
|
else:
|
||||||
|
await asyncio.gather(*[c.start() for c in clients])
|
||||||
|
|
||||||
await idle()
|
await idle()
|
||||||
|
|
||||||
for c in clients:
|
if sequential:
|
||||||
await c.stop()
|
for c in clients:
|
||||||
|
await c.stop()
|
||||||
|
else:
|
||||||
|
await asyncio.gather(*[c.stop() for c in clients])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user