ez-a-sync 0.32.29__cp310-cp310-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ez-a-sync might be problematic. Click here for more details.

Files changed (177) hide show
  1. a_sync/ENVIRONMENT_VARIABLES.py +42 -0
  2. a_sync/__init__.pxd +2 -0
  3. a_sync/__init__.py +145 -0
  4. a_sync/_smart.c +22803 -0
  5. a_sync/_smart.cp310-win_amd64.pyd +0 -0
  6. a_sync/_smart.pxd +2 -0
  7. a_sync/_smart.pyi +202 -0
  8. a_sync/_smart.pyx +674 -0
  9. a_sync/_typing.py +258 -0
  10. a_sync/a_sync/__init__.py +60 -0
  11. a_sync/a_sync/_descriptor.c +20528 -0
  12. a_sync/a_sync/_descriptor.cp310-win_amd64.pyd +0 -0
  13. a_sync/a_sync/_descriptor.pyi +33 -0
  14. a_sync/a_sync/_descriptor.pyx +422 -0
  15. a_sync/a_sync/_flags.c +6074 -0
  16. a_sync/a_sync/_flags.cp310-win_amd64.pyd +0 -0
  17. a_sync/a_sync/_flags.pxd +3 -0
  18. a_sync/a_sync/_flags.pyx +92 -0
  19. a_sync/a_sync/_helpers.c +14521 -0
  20. a_sync/a_sync/_helpers.cp310-win_amd64.pyd +0 -0
  21. a_sync/a_sync/_helpers.pxd +3 -0
  22. a_sync/a_sync/_helpers.pyi +10 -0
  23. a_sync/a_sync/_helpers.pyx +167 -0
  24. a_sync/a_sync/_kwargs.c +12194 -0
  25. a_sync/a_sync/_kwargs.cp310-win_amd64.pyd +0 -0
  26. a_sync/a_sync/_kwargs.pxd +2 -0
  27. a_sync/a_sync/_kwargs.pyx +64 -0
  28. a_sync/a_sync/_meta.py +210 -0
  29. a_sync/a_sync/abstract.c +12411 -0
  30. a_sync/a_sync/abstract.cp310-win_amd64.pyd +0 -0
  31. a_sync/a_sync/abstract.pyi +141 -0
  32. a_sync/a_sync/abstract.pyx +221 -0
  33. a_sync/a_sync/base.c +14932 -0
  34. a_sync/a_sync/base.cp310-win_amd64.pyd +0 -0
  35. a_sync/a_sync/base.pyi +60 -0
  36. a_sync/a_sync/base.pyx +271 -0
  37. a_sync/a_sync/config.py +168 -0
  38. a_sync/a_sync/decorator.py +651 -0
  39. a_sync/a_sync/flags.c +5272 -0
  40. a_sync/a_sync/flags.cp310-win_amd64.pyd +0 -0
  41. a_sync/a_sync/flags.pxd +72 -0
  42. a_sync/a_sync/flags.pyi +74 -0
  43. a_sync/a_sync/flags.pyx +72 -0
  44. a_sync/a_sync/function.c +37846 -0
  45. a_sync/a_sync/function.cp310-win_amd64.pyd +0 -0
  46. a_sync/a_sync/function.pxd +28 -0
  47. a_sync/a_sync/function.pyi +571 -0
  48. a_sync/a_sync/function.pyx +1381 -0
  49. a_sync/a_sync/method.c +29774 -0
  50. a_sync/a_sync/method.cp310-win_amd64.pyd +0 -0
  51. a_sync/a_sync/method.pxd +9 -0
  52. a_sync/a_sync/method.pyi +525 -0
  53. a_sync/a_sync/method.pyx +1023 -0
  54. a_sync/a_sync/modifiers/__init__.pxd +1 -0
  55. a_sync/a_sync/modifiers/__init__.py +101 -0
  56. a_sync/a_sync/modifiers/cache/__init__.py +160 -0
  57. a_sync/a_sync/modifiers/cache/memory.py +165 -0
  58. a_sync/a_sync/modifiers/limiter.py +132 -0
  59. a_sync/a_sync/modifiers/manager.c +16149 -0
  60. a_sync/a_sync/modifiers/manager.cp310-win_amd64.pyd +0 -0
  61. a_sync/a_sync/modifiers/manager.pxd +5 -0
  62. a_sync/a_sync/modifiers/manager.pyi +219 -0
  63. a_sync/a_sync/modifiers/manager.pyx +299 -0
  64. a_sync/a_sync/modifiers/semaphores.py +173 -0
  65. a_sync/a_sync/property.c +27260 -0
  66. a_sync/a_sync/property.cp310-win_amd64.pyd +0 -0
  67. a_sync/a_sync/property.pyi +376 -0
  68. a_sync/a_sync/property.pyx +819 -0
  69. a_sync/a_sync/singleton.py +63 -0
  70. a_sync/aliases.py +3 -0
  71. a_sync/async_property/__init__.pxd +1 -0
  72. a_sync/async_property/__init__.py +1 -0
  73. a_sync/async_property/cached.c +20386 -0
  74. a_sync/async_property/cached.cp310-win_amd64.pyd +0 -0
  75. a_sync/async_property/cached.pxd +10 -0
  76. a_sync/async_property/cached.pyi +45 -0
  77. a_sync/async_property/cached.pyx +178 -0
  78. a_sync/async_property/proxy.c +34654 -0
  79. a_sync/async_property/proxy.cp310-win_amd64.pyd +0 -0
  80. a_sync/async_property/proxy.pxd +2 -0
  81. a_sync/async_property/proxy.pyi +124 -0
  82. a_sync/async_property/proxy.pyx +474 -0
  83. a_sync/asyncio/__init__.pxd +6 -0
  84. a_sync/asyncio/__init__.py +164 -0
  85. a_sync/asyncio/as_completed.c +18841 -0
  86. a_sync/asyncio/as_completed.cp310-win_amd64.pyd +0 -0
  87. a_sync/asyncio/as_completed.pxd +8 -0
  88. a_sync/asyncio/as_completed.pyi +109 -0
  89. a_sync/asyncio/as_completed.pyx +269 -0
  90. a_sync/asyncio/create_task.c +15902 -0
  91. a_sync/asyncio/create_task.cp310-win_amd64.pyd +0 -0
  92. a_sync/asyncio/create_task.pxd +2 -0
  93. a_sync/asyncio/create_task.pyi +51 -0
  94. a_sync/asyncio/create_task.pyx +271 -0
  95. a_sync/asyncio/gather.c +16679 -0
  96. a_sync/asyncio/gather.cp310-win_amd64.pyd +0 -0
  97. a_sync/asyncio/gather.pyi +107 -0
  98. a_sync/asyncio/gather.pyx +218 -0
  99. a_sync/asyncio/igather.c +12676 -0
  100. a_sync/asyncio/igather.cp310-win_amd64.pyd +0 -0
  101. a_sync/asyncio/igather.pxd +1 -0
  102. a_sync/asyncio/igather.pyi +7 -0
  103. a_sync/asyncio/igather.pyx +182 -0
  104. a_sync/asyncio/sleep.c +9593 -0
  105. a_sync/asyncio/sleep.cp310-win_amd64.pyd +0 -0
  106. a_sync/asyncio/sleep.pyi +14 -0
  107. a_sync/asyncio/sleep.pyx +49 -0
  108. a_sync/debugging.c +15362 -0
  109. a_sync/debugging.cp310-win_amd64.pyd +0 -0
  110. a_sync/debugging.pyi +76 -0
  111. a_sync/debugging.pyx +107 -0
  112. a_sync/exceptions.c +13312 -0
  113. a_sync/exceptions.cp310-win_amd64.pyd +0 -0
  114. a_sync/exceptions.pyi +376 -0
  115. a_sync/exceptions.pyx +446 -0
  116. a_sync/executor.py +619 -0
  117. a_sync/functools.c +12738 -0
  118. a_sync/functools.cp310-win_amd64.pyd +0 -0
  119. a_sync/functools.pxd +7 -0
  120. a_sync/functools.pyi +33 -0
  121. a_sync/functools.pyx +139 -0
  122. a_sync/future.py +1497 -0
  123. a_sync/iter.c +37271 -0
  124. a_sync/iter.cp310-win_amd64.pyd +0 -0
  125. a_sync/iter.pxd +11 -0
  126. a_sync/iter.pyi +370 -0
  127. a_sync/iter.pyx +981 -0
  128. a_sync/primitives/__init__.pxd +1 -0
  129. a_sync/primitives/__init__.py +53 -0
  130. a_sync/primitives/_debug.c +15757 -0
  131. a_sync/primitives/_debug.cp310-win_amd64.pyd +0 -0
  132. a_sync/primitives/_debug.pxd +12 -0
  133. a_sync/primitives/_debug.pyi +52 -0
  134. a_sync/primitives/_debug.pyx +223 -0
  135. a_sync/primitives/_loggable.c +11529 -0
  136. a_sync/primitives/_loggable.cp310-win_amd64.pyd +0 -0
  137. a_sync/primitives/_loggable.pxd +4 -0
  138. a_sync/primitives/_loggable.pyi +66 -0
  139. a_sync/primitives/_loggable.pyx +102 -0
  140. a_sync/primitives/locks/__init__.pxd +8 -0
  141. a_sync/primitives/locks/__init__.py +17 -0
  142. a_sync/primitives/locks/counter.c +17679 -0
  143. a_sync/primitives/locks/counter.cp310-win_amd64.pyd +0 -0
  144. a_sync/primitives/locks/counter.pxd +12 -0
  145. a_sync/primitives/locks/counter.pyi +151 -0
  146. a_sync/primitives/locks/counter.pyx +260 -0
  147. a_sync/primitives/locks/event.c +17063 -0
  148. a_sync/primitives/locks/event.cp310-win_amd64.pyd +0 -0
  149. a_sync/primitives/locks/event.pxd +22 -0
  150. a_sync/primitives/locks/event.pyi +43 -0
  151. a_sync/primitives/locks/event.pyx +185 -0
  152. a_sync/primitives/locks/prio_semaphore.c +25590 -0
  153. a_sync/primitives/locks/prio_semaphore.cp310-win_amd64.pyd +0 -0
  154. a_sync/primitives/locks/prio_semaphore.pxd +25 -0
  155. a_sync/primitives/locks/prio_semaphore.pyi +217 -0
  156. a_sync/primitives/locks/prio_semaphore.pyx +597 -0
  157. a_sync/primitives/locks/semaphore.c +26509 -0
  158. a_sync/primitives/locks/semaphore.cp310-win_amd64.pyd +0 -0
  159. a_sync/primitives/locks/semaphore.pxd +21 -0
  160. a_sync/primitives/locks/semaphore.pyi +197 -0
  161. a_sync/primitives/locks/semaphore.pyx +454 -0
  162. a_sync/primitives/queue.py +1022 -0
  163. a_sync/py.typed +0 -0
  164. a_sync/sphinx/__init__.py +3 -0
  165. a_sync/sphinx/ext.py +289 -0
  166. a_sync/task.py +932 -0
  167. a_sync/utils/__init__.py +105 -0
  168. a_sync/utils/iterators.py +297 -0
  169. a_sync/utils/repr.c +15799 -0
  170. a_sync/utils/repr.cp310-win_amd64.pyd +0 -0
  171. a_sync/utils/repr.pyi +2 -0
  172. a_sync/utils/repr.pyx +73 -0
  173. ez_a_sync-0.32.29.dist-info/METADATA +367 -0
  174. ez_a_sync-0.32.29.dist-info/RECORD +177 -0
  175. ez_a_sync-0.32.29.dist-info/WHEEL +5 -0
  176. ez_a_sync-0.32.29.dist-info/licenses/LICENSE.txt +17 -0
  177. ez_a_sync-0.32.29.dist-info/top_level.txt +1 -0
@@ -0,0 +1,107 @@
1
+ """
2
+ This module provides an enhanced version of :func:`asyncio.gather`.
3
+ """
4
+
5
+ from a_sync._typing import *
6
+ from typing import Any, Awaitable, Dict, List, Mapping, overload
7
+
8
+ __all__ = ["gather", "gather_mapping"]
9
+
10
+ class tqdm_asyncio:
11
+ @staticmethod
12
+ async def gather(*args, **kwargs) -> None: ...
13
+
14
+ Excluder = Callable[[T], bool]
15
+
16
+ @overload
17
+ async def gather(
18
+ awaitables: Mapping[K, Awaitable[V]],
19
+ return_exceptions: bool = False,
20
+ exclude_if: Optional[Excluder[V]] = None,
21
+ tqdm: bool = False,
22
+ **tqdm_kwargs: Any
23
+ ) -> Dict[K, V]:
24
+ """
25
+ Concurrently awaits a k:v mapping of awaitables and returns the results.
26
+
27
+ Args:
28
+ awaitables (Mapping[K, Awaitable[V]]): A mapping of keys to awaitable objects.
29
+ return_exceptions (bool, optional): If True, exceptions are returned as results instead of raising them. Defaults to False.
30
+ exclude_if (Optional[Excluder[V]], optional): A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None. Note: This is only applied when the input is not a mapping.
31
+ tqdm (bool, optional): If True, enables progress reporting using tqdm. Defaults to False.
32
+ **tqdm_kwargs: Additional keyword arguments for tqdm if progress reporting is enabled.
33
+
34
+ Examples:
35
+ Awaiting a mapping of awaitables:
36
+
37
+ >>> mapping = {'key1': thing1(), 'key2': thing2()}
38
+ >>> results = await gather(mapping)
39
+ >>> results
40
+ {'key1': 'result', 'key2': 123}
41
+
42
+ See Also:
43
+ :func:`asyncio.gather`
44
+ """
45
+
46
+ @overload
47
+ async def gather(
48
+ *awaitables: Awaitable[T],
49
+ return_exceptions: bool = False,
50
+ exclude_if: Optional[Excluder[T]] = None,
51
+ tqdm: bool = False,
52
+ **tqdm_kwargs: Any
53
+ ) -> List[T]:
54
+ """
55
+ Concurrently awaits a series of awaitable objects and returns the results.
56
+
57
+ Args:
58
+ *awaitables (Awaitable[T]): The awaitables to await concurrently.
59
+ return_exceptions (bool, optional): If True, exceptions are returned as results instead of raising them. Defaults to False.
60
+ exclude_if (Optional[Excluder[T]], optional): A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None.
61
+ tqdm (bool, optional): If True, enables progress reporting using tqdm. Defaults to False.
62
+ **tqdm_kwargs: Additional keyword arguments for tqdm if progress reporting is enabled.
63
+
64
+ Examples:
65
+ Awaiting individual awaitables:
66
+
67
+ >>> results = await gather(thing1(), thing2())
68
+ >>> results
69
+ ['result', 123]
70
+
71
+ See Also:
72
+ :func:`asyncio.gather`
73
+ """
74
+
75
+ async def gather_mapping(
76
+ mapping: Mapping[K, Awaitable[V]],
77
+ return_exceptions: bool = False,
78
+ exclude_if: Optional[Excluder[V]] = None,
79
+ tqdm: bool = False,
80
+ **tqdm_kwargs: Any
81
+ ) -> Dict[K, V]:
82
+ """
83
+ Concurrently awaits a mapping of awaitable objects and returns a dictionary of results.
84
+
85
+ This function is designed to await a mapping of awaitable objects, where each key-value pair represents a unique awaitable. It enables concurrent execution and gathers results into a dictionary.
86
+
87
+ Args:
88
+ mapping (Mapping[K, Awaitable[V]]): A dictionary-like object where keys are of type K and values are awaitable objects of type V.
89
+ return_exceptions (bool, optional): If True, exceptions are returned as results instead of raising them. Defaults to False.
90
+ exclude_if (Optional[Excluder[V]], optional): A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None. Note: This is not applied when the input is a mapping.
91
+ tqdm (bool, optional): If True, enables progress reporting using tqdm. Defaults to False.
92
+ **tqdm_kwargs: Additional keyword arguments for tqdm if progress reporting is enabled.
93
+
94
+ Example:
95
+ The \'results\' dictionary will contain the awaited results, where keys match the keys in the \'mapping\' and values contain the results of the corresponding awaitables.
96
+
97
+ >>> mapping = {\'task1\': async_function1(), \'task2\': async_function2(), \'task3\': async_function3()}
98
+ >>> results = await gather_mapping(mapping)
99
+ >>> results
100
+ {\'task1\': "result", \'task2\': 123, \'task3\': None}
101
+
102
+ See Also:
103
+ :func:`asyncio.gather`
104
+ """
105
+
106
+ def cgather(*coros_or_futures: Awaitable[T], return_exceptions: bool = False) -> Awaitable[List[T]]:
107
+ """`asyncio.gather` implemented in c"""
@@ -0,0 +1,218 @@
1
+ # cython: boundscheck=False
2
+ """
3
+ This module provides an enhanced version of :func:`asyncio.gather`.
4
+ """
5
+ from itertools import filterfalse
6
+ from typing import Any, Awaitable, Dict, List, Mapping, Union, overload
7
+
8
+ from a_sync._typing import *
9
+ from a_sync.asyncio cimport as_completed_mapping, cigather
10
+
11
+ try:
12
+ from tqdm.asyncio import tqdm_asyncio
13
+ except ImportError as e:
14
+
15
+ class tqdm_asyncio: # type: ignore [no-redef]
16
+ @staticmethod
17
+ async def gather(*args, **kwargs):
18
+ raise ImportError(
19
+ "You must have tqdm installed in order to use this feature"
20
+ )
21
+
22
+
23
+ Excluder = Callable[[T], bool]
24
+
25
+
26
+ @overload
27
+ async def gather(
28
+ awaitables: Mapping[K, Awaitable[V]],
29
+ bint return_exceptions = False,
30
+ exclude_if: Optional[Excluder[V]] = None,
31
+ tqdm: bool = False,
32
+ **tqdm_kwargs: Any,
33
+ ) -> Dict[K, V]:
34
+ """
35
+ Concurrently awaits a k:v mapping of awaitables and returns the results.
36
+
37
+ Args:
38
+ awaitables (Mapping[K, Awaitable[V]]): A mapping of keys to awaitable objects.
39
+ return_exceptions (bool, optional): If True, exceptions are returned as results instead of raising them. Defaults to False.
40
+ exclude_if (Optional[Excluder[V]], optional): A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None. Note: This is only applied when the input is not a mapping.
41
+ tqdm (bool, optional): If True, enables progress reporting using tqdm. Defaults to False.
42
+ **tqdm_kwargs: Additional keyword arguments for tqdm if progress reporting is enabled.
43
+
44
+ Examples:
45
+ Awaiting a mapping of awaitables:
46
+
47
+ >>> mapping = {'key1': thing1(), 'key2': thing2()}
48
+ >>> results = await gather(mapping)
49
+ >>> results
50
+ {'key1': 'result', 'key2': 123}
51
+
52
+ See Also:
53
+ :func:`asyncio.gather`
54
+ """
55
+
56
+
57
+ @overload
58
+ async def gather(
59
+ *awaitables: Awaitable[T],
60
+ bint return_exceptions = False,
61
+ exclude_if: Optional[Excluder[T]] = None,
62
+ tqdm: bool = False,
63
+ **tqdm_kwargs: Any,
64
+ ) -> List[T]:
65
+ """
66
+ Concurrently awaits a series of awaitable objects and returns the results.
67
+
68
+ Args:
69
+ *awaitables (Awaitable[T]): The awaitables to await concurrently.
70
+ return_exceptions (bool, optional): If True, exceptions are returned as results instead of raising them. Defaults to False.
71
+ exclude_if (Optional[Excluder[T]], optional): A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None.
72
+ tqdm (bool, optional): If True, enables progress reporting using tqdm. Defaults to False.
73
+ **tqdm_kwargs: Additional keyword arguments for tqdm if progress reporting is enabled.
74
+
75
+ Examples:
76
+ Awaiting individual awaitables:
77
+
78
+ >>> results = await gather(thing1(), thing2())
79
+ >>> results
80
+ ['result', 123]
81
+
82
+ See Also:
83
+ :func:`asyncio.gather`
84
+ """
85
+
86
+
87
+ async def gather(
88
+ *awaitables: Union[Awaitable[T], Mapping[K, Awaitable[V]]],
89
+ bint return_exceptions = False,
90
+ exclude_if: Optional[Excluder[T]] = None,
91
+ tqdm: bool = False,
92
+ **tqdm_kwargs: Any,
93
+ ) -> Union[List[T], Dict[K, V]]:
94
+ """
95
+ Concurrently awaits a list of awaitable objects or a k:v mapping of awaitables, and returns the results.
96
+
97
+ This function extends Python's :func:`asyncio.gather`, providing additional features for handling either individual
98
+ awaitable objects or a single mapping of awaitables.
99
+
100
+ Differences from :func:`asyncio.gather`:
101
+ - Uses type hints for use with static type checkers.
102
+ - Supports gathering either individual awaitables or a k:v mapping of awaitables.
103
+ - Provides progress reporting using tqdm if 'tqdm' is set to True.
104
+ - Allows exclusion of results based on a condition using the 'exclude_if' parameter. Note: This is only applied when the input is not a mapping.
105
+
106
+ Args:
107
+ *awaitables (Union[Awaitable[T], Mapping[K, Awaitable[V]]]): The awaitables to await concurrently. It can be a list of individual awaitables or a single mapping of awaitables.
108
+ return_exceptions (bool, optional): If True, exceptions are returned as results instead of raising them. Defaults to False.
109
+ exclude_if (Optional[Excluder[T]], optional): A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None. Note: This is only applied when the input is not a mapping.
110
+ tqdm (bool, optional): If True, enables progress reporting using tqdm. Defaults to False.
111
+ **tqdm_kwargs: Additional keyword arguments for tqdm if progress reporting is enabled.
112
+
113
+ Examples:
114
+ Awaiting individual awaitables:
115
+
116
+ >>> results = await gather(thing1(), thing2())
117
+ >>> results
118
+ ['result', 123]
119
+
120
+ Awaiting a mapping of awaitables:
121
+
122
+ >>> mapping = {'key1': thing1(), 'key2': thing2()}
123
+ >>> results = await gather(mapping)
124
+ >>> results
125
+ {'key1': 'result', 'key2': 123}
126
+
127
+ See Also:
128
+ :func:`asyncio.gather`
129
+ """
130
+ if is_mapping := _is_mapping(awaitables):
131
+ results = await gather_mapping(
132
+ awaitables[0],
133
+ return_exceptions=return_exceptions,
134
+ exclude_if=exclude_if,
135
+ tqdm=tqdm,
136
+ **tqdm_kwargs,
137
+ )
138
+ elif tqdm:
139
+ if return_exceptions:
140
+ awaitables = map(_exc_wrap, awaitables)
141
+ results = await tqdm_asyncio.gather(*awaitables, **tqdm_kwargs)
142
+ else:
143
+ results = await cigather(awaitables, return_exceptions=return_exceptions)
144
+
145
+ if exclude_if and not is_mapping:
146
+ return list(filterfalse(exclude_if, results))
147
+
148
+ return results
149
+
150
+
151
+ async def gather_mapping(
152
+ mapping: Mapping[K, Awaitable[V]],
153
+ bint return_exceptions = False,
154
+ exclude_if: Optional[Excluder[V]] = None,
155
+ tqdm: bool = False,
156
+ **tqdm_kwargs: Any,
157
+ ) -> Dict[K, V]:
158
+ """
159
+ Concurrently awaits a mapping of awaitable objects and returns a dictionary of results.
160
+
161
+ This function is designed to await a mapping of awaitable objects, where each key-value pair represents a unique awaitable. It enables concurrent execution and gathers results into a dictionary.
162
+
163
+ Args:
164
+ mapping (Mapping[K, Awaitable[V]]): A dictionary-like object where keys are of type K and values are awaitable objects of type V.
165
+ return_exceptions (bool, optional): If True, exceptions are returned as results instead of raising them. Defaults to False.
166
+ exclude_if (Optional[Excluder[V]], optional): A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None. Note: This is not applied when the input is a mapping.
167
+ tqdm (bool, optional): If True, enables progress reporting using tqdm. Defaults to False.
168
+ **tqdm_kwargs: Additional keyword arguments for tqdm if progress reporting is enabled.
169
+
170
+ Example:
171
+ The 'results' dictionary will contain the awaited results, where keys match the keys in the 'mapping' and values contain the results of the corresponding awaitables.
172
+
173
+ >>> mapping = {'task1': async_function1(), 'task2': async_function2(), 'task3': async_function3()}
174
+ >>> results = await gather_mapping(mapping)
175
+ >>> results
176
+ {'task1': "result", 'task2': 123, 'task3': None}
177
+
178
+ See Also:
179
+ :func:`asyncio.gather`
180
+ """
181
+ results = {
182
+ k: v
183
+ async for k, v in as_completed_mapping(
184
+ mapping=mapping,
185
+ timeout=0,
186
+ return_exceptions=return_exceptions,
187
+ aiter=True,
188
+ tqdm=tqdm,
189
+ tqdm_kwargs=tqdm_kwargs,
190
+ )
191
+ if exclude_if is None or not exclude_if(v)
192
+ }
193
+ # return data in same order as input mapping
194
+ return {k: results[k] for k in mapping}
195
+
196
+
197
+ def cgather(*coros_or_futures: Awaitable[T], bint return_exceptions = False) -> Awaitable[List[T]]:
198
+ """`asyncio.gather` implemented in c"""
199
+ return cigather(coros_or_futures, return_exceptions=return_exceptions)
200
+
201
+
202
+ cdef inline bint _is_mapping(tuple awaitables):
203
+ return len(awaitables) == 1 and isinstance(awaitables[0], Mapping)
204
+
205
+
206
+ async def _exc_wrap(awaitable: Awaitable[T]) -> Union[T, Exception]:
207
+ """Wraps an awaitable to catch exceptions and return them instead of raising.
208
+
209
+ Args:
210
+ awaitable: The awaitable to wrap.
211
+
212
+ Returns:
213
+ The result of the awaitable or the exception if one is raised.
214
+ """
215
+ try:
216
+ return await awaitable
217
+ except Exception as e:
218
+ return e