File tree Expand file tree Collapse file tree
pyrogram/methods/utilities Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
1920from typing import List
2021
2122import pyrogram
2223from .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 ])
You can’t perform that action at this time.
0 commit comments