@@ -90,7 +90,7 @@ async def run_async_cm(self):
90
90
91
91
def __enter__ (self ) -> T_co :
92
92
self ._enter_future = Future ()
93
- self ._exit_future = self ._portal .spawn_task (self .run_async_cm )
93
+ self ._exit_future = self ._portal .start_task_soon (self .run_async_cm )
94
94
cm = self ._enter_future .result ()
95
95
return cast (T_co , cm )
96
96
@@ -219,9 +219,30 @@ def call(self, func, *args):
219
219
the event loop thread
220
220
221
221
"""
222
- return self .spawn_task (func , * args ).result ()
222
+ return self .start_task_soon (func , * args ).result ()
223
223
224
224
def spawn_task (self , func : Callable [..., Coroutine ], * args , name = None ) -> Future :
225
+ """
226
+ Deprecated alias for :meth:`start_task_soon`.
227
+
228
+ :param func: the target coroutine function
229
+ :param args: positional arguments passed to ``func``
230
+ :param name: name of the task (will be coerced to a string if not ``None``)
231
+ :return: a future that resolves with the return value of the callable if the task completes
232
+ successfully, or with the exception raised in the task
233
+ :raises RuntimeError: if the portal is not running or if this method is called from within
234
+ the event loop thread
235
+
236
+ .. versionadded:: 2.1
237
+ .. deprecated:: 3.0
238
+ Use :meth:`start_task_soon` instead. If your code needs AnyIO 2 compatibility, you
239
+ can keep using this until AnyIO 4.
240
+
241
+ """
242
+ warn ('spawn_task() is deprecated -- use start_task_soon() instead' , DeprecationWarning )
243
+ return self .start_task_soon (func , * args , name = name )
244
+
245
+ def start_task_soon (self , func : Callable [..., Coroutine ], * args , name = None ) -> Future :
225
246
"""
226
247
Spawn a task in the portal's task group.
227
248
@@ -236,9 +257,7 @@ def spawn_task(self, func: Callable[..., Coroutine], *args, name=None) -> Future
236
257
:raises RuntimeError: if the portal is not running or if this method is called from within
237
258
the event loop thread
238
259
239
- .. versionadded:: 2.1
240
- .. versionchanged:: 3.0
241
- Added the ``name`` argument.
260
+ .. versionadded:: 3.0
242
261
243
262
"""
244
263
self ._check_running ()
0 commit comments