Skip to content

Commit

Permalink
added init_property method
Browse files Browse the repository at this point in the history
  • Loading branch information
lferraz committed Apr 30, 2023
1 parent 922b94c commit 8086176
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions limbus/core/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 8086176

Please sign in to comment.