mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-21 00:40:01 +02:00
adds autostart flag to task
This commit is contained in:
parent
e4a3cf341f
commit
1e02f12794
@ -26,6 +26,6 @@ def task(
|
|||||||
logger.info("Task '%s' was cancelled", func.__name__)
|
logger.info("Task '%s' was cancelled", func.__name__)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Task(wrapper)
|
return Task(wrapper, autostart=autostart)
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -41,6 +41,8 @@ class Task(pydase.DataService, Generic[P, R]):
|
|||||||
self,
|
self,
|
||||||
func: Callable[Concatenate[Any, P], Coroutine[None, None, R | None]]
|
func: Callable[Concatenate[Any, P], Coroutine[None, None, R | None]]
|
||||||
| Callable[P, Coroutine[None, None, R | None]],
|
| Callable[P, Coroutine[None, None, R | None]],
|
||||||
|
*,
|
||||||
|
autostart: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._func_name = func.__name__
|
self._func_name = func.__name__
|
||||||
@ -53,6 +55,8 @@ class Task(pydase.DataService, Generic[P, R]):
|
|||||||
self._task: asyncio.Task[R] | None = None
|
self._task: asyncio.Task[R] | None = None
|
||||||
self._status = TaskStatus.NOT_RUNNING
|
self._status = TaskStatus.NOT_RUNNING
|
||||||
self._result: R | None = None
|
self._result: R | None = None
|
||||||
|
if autostart:
|
||||||
|
self.start()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def status(self) -> TaskStatus:
|
def status(self) -> TaskStatus:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user