-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Motivation
The GenericActor pattern causes a few problem today:
- The logic is "too magic" and hard to follow
- A generic actor is impossible to type check
- The pattern is not thread safe
Proposal
- Only support function actors
- Provide a helper function that can create an actor given a class. Code draft below
ActorParams = ParamSpec("ActorParams")
ReturnT = TypeVar("ReturnT")
class ClassActorP(Protocol[ActorParams, ReturnT]):
def __init__(*args: ActorParams.args, **kwargs: ActorParams.kwargs) -> None:
...
def perform(self) -> ReturnT:
...
def get_actor_from_class(
actor_class: Type[ClassActorP[ActorParams, ReturnT]],
**options: Expand[OptionsT]
) -> Actor[ActorParams, ReturnT]:
def _actor(*args: ActorParams.args, **kwargs: ActorParams.kwargs) -> ReturnT:
return actor_class(*args, **kwargs).perform()
return _actorExample:
@attr.s(auto_attribs=True)
class Add:
x: int
y: int
def perform(self) -> int:
return self.x + self.y
add = get_actor_from_class(Add, max_retries=5)Metadata
Metadata
Assignees
Labels
No labels