Skip to content

Commit f628375

Browse files
committed
Add sequential parameter to compose()
1 parent 5681cce commit f628375

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

pyrogram/methods/utilities/compose.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
import asyncio
1920
from typing import List
2021

2122
import pyrogram
2223
from .idle import idle
2324

2425

25-
async def compose(clients: List["pyrogram.Client"]):
26+
async def compose(
27+
clients: List["pyrogram.Client"],
28+
sequential: bool = False
29+
):
2630
"""Run multiple clients at once.
2731
2832
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"]):
3337
clients (List of :obj:`~pyrogram.Client`):
3438
A list of client objects to run.
3539
40+
sequential (``bool``, *optional*):
41+
Pass True to run clients sequentially.
42+
Defaults to False (run clients concurrently)
43+
3644
Example:
3745
.. code-block:: python
3846
@@ -53,10 +61,16 @@ async def main():
5361
asyncio.run(main())
5462
5563
"""
56-
for c in clients:
57-
await c.start()
64+
if sequential:
65+
for c in clients:
66+
await c.start()
67+
else:
68+
await asyncio.gather(*[c.start() for c in clients])
5869

5970
await idle()
6071

61-
for c in clients:
62-
await c.stop()
72+
if sequential:
73+
for c in clients:
74+
await c.stop()
75+
else:
76+
await asyncio.gather(*[c.stop() for c in clients])

0 commit comments

Comments
 (0)