diff --git a/limbus/core/param.py b/limbus/core/param.py index d426ed5..23b9d91 100644 --- a/limbus/core/param.py +++ b/limbus/core/param.py @@ -228,7 +228,7 @@ def __eq__(self, other: Any) -> bool: class Param(ABC): - """Class to store data for each parameter. + """Base class to store data for each parameter. Args: name: name of the parameter. @@ -490,8 +490,24 @@ def disconnect(self, dst: "Param" | IterableParam) -> None: class PropertyParam(Param): """Class to manage the comunication for each property parameter.""" + def init_property(self, value: Any) -> None: + """Initialize the property with the given value. + + This method should be called before running the component to init the property. + So, it is not running the callback function. + + """ + assert self._parent is not None + if self._parent.executions_counter > 0: + raise RuntimeError("The property can only be initialized before running the component.") + self.value = value + async def set_property(self, value: Any) -> None: - """Set the value of the property.""" + """Set the value of the property. + + Note: using this method is the only way to run the callback function. + + """ assert self._parent is not None if self._callback is None: self.value = value @@ -503,7 +519,11 @@ class InputParam(Param): """Class to manage the comunication for each input parameter.""" async def receive(self) -> Any: - """Wait until the input param receives a value from the connected output param.""" + """Wait until the input param receives a value from the connected output param. + + Note that using this metohd will run the callback function as soon as a new value is received. + + """ assert self._parent is not None self._parent._Component__num_params_waiting_to_receive += 1 if self.references: @@ -560,11 +580,10 @@ async def receive(self) -> Any: ref.sent.clear() # allow to know to the sender that it can send again else: value = self.value - await self._are_all_waiting_params_received() if self._callback is not None: # specific callback for this param value = await self._callback(self._parent, value) - + await self._are_all_waiting_params_received() if self._parent.pipeline and self._parent.pipeline.param_received_user_hook: # hook from the pipeline, all the components and input params run the same code await self._parent.pipeline.param_received_user_hook(self) @@ -582,7 +601,11 @@ class OutputParam(Param): """Class to manage the comunication for each output parameter.""" async def send(self, value: Any) -> None: - """Send the value of this param to the connected input params.""" + """Send the value of this param to the connected input params. + + Note that using this metohd will run the callback function as soon as a new value is received. + + """ assert self._parent is not None if self._callback is None: self.value = value # set the value for the param