1- import asyncio
2- import functools
31import typing as t
42from functools import update_wrapper
53
64import click
75from ellar .threading .sync_worker import (
8- execute_async_context_manager_with_sync_worker ,
9- execute_coroutine_with_sync_worker ,
6+ execute_async_context_manager ,
107)
118
129from ellar_cli .constants import ELLAR_META
@@ -24,32 +21,9 @@ def decorator(__ctx: click.Context, *args: t.Any, **kwargs: t.Any) -> t.Any:
2421
2522 if meta_ and meta_ .has_meta :
2623 __ctx .with_resource (
27- execute_async_context_manager_with_sync_worker (
28- meta_ .get_application_context ()
29- )
24+ execute_async_context_manager (meta_ .get_application_context ())
3025 )
3126
3227 return __ctx .invoke (f , * args , ** kwargs )
3328
3429 return update_wrapper (decorator , f )
35-
36-
37- def run_as_async (f : t .Callable ) -> t .Callable :
38- """
39- Runs async click commands
40-
41- eg:
42-
43- @click.command()
44- @click.argument('name')
45- @click.run_as_async
46- async def print_name(name: str):
47- click.echo(f'Hello {name}, this is an async command.')
48- """
49- assert asyncio .iscoroutinefunction (f ), "Decorated function must be Coroutine"
50-
51- @functools .wraps (f )
52- def _decorator (* args : t .Any , ** kw : t .Any ) -> t .Any :
53- return execute_coroutine_with_sync_worker (f (* args , ** kw ))
54-
55- return _decorator
0 commit comments