Minor fixes
This commit is contained in:
@@ -51,8 +51,6 @@ class Host:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_app(cls, func: Callable, *args, **kwargs):
|
def run_app(cls, func: Callable, *args, **kwargs):
|
||||||
loop = cls.get_loop()
|
|
||||||
|
|
||||||
cls.run_start_tasks()
|
cls.run_start_tasks()
|
||||||
cls.run_hosted_services()
|
cls.run_hosted_services()
|
||||||
|
|
||||||
@@ -61,8 +59,7 @@ class Host:
|
|||||||
if asyncio.iscoroutinefunction(func):
|
if asyncio.iscoroutinefunction(func):
|
||||||
app_task = asyncio.create_task(func(*args, **kwargs))
|
app_task = asyncio.create_task(func(*args, **kwargs))
|
||||||
else:
|
else:
|
||||||
loop = asyncio.get_running_loop()
|
app_task = cls.get_loop().run_in_executor(None, func, *args, **kwargs)
|
||||||
app_task = loop.run_in_executor(None, func, *args, **kwargs)
|
|
||||||
|
|
||||||
await asyncio.wait(
|
await asyncio.wait(
|
||||||
[app_task, *cls._tasks.values()],
|
[app_task, *cls._tasks.values()],
|
||||||
@@ -73,11 +70,11 @@ class Host:
|
|||||||
finally:
|
finally:
|
||||||
await cls._stop_all()
|
await cls._stop_all()
|
||||||
|
|
||||||
loop.run_until_complete(runner())
|
cls.get_loop().run_until_complete(runner())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, func: Callable, *args, **kwargs):
|
def run(cls, func: Callable, *args, **kwargs):
|
||||||
if asyncio.iscoroutinefunction(func):
|
if asyncio.iscoroutinefunction(func):
|
||||||
return cls._loop.run_until_complete(func(*args, **kwargs))
|
return cls.get_loop().run_until_complete(func(*args, **kwargs))
|
||||||
|
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
@@ -161,7 +161,7 @@ class ServiceProvider:
|
|||||||
implementations = []
|
implementations = []
|
||||||
if typing.get_origin(service_type) == list:
|
if typing.get_origin(service_type) == list:
|
||||||
raise Exception(f"Invalid type {service_type}! Expected single type not list of type")
|
raise Exception(f"Invalid type {service_type}! Expected single type not list of type")
|
||||||
implementations.extend(self._get_services(service_type, None, *args, **kwargs))
|
implementations.extend(self._get_services(service_type, *args, **kwargs))
|
||||||
return implementations
|
return implementations
|
||||||
|
|
||||||
def get_service_types(self, service_type: Type[T]) -> list[Type[T]]:
|
def get_service_types(self, service_type: Type[T]) -> list[Type[T]]:
|
||||||
|
|||||||
Reference in New Issue
Block a user