Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate GenericActor #311

Open
mehdigmira opened this issue Oct 17, 2022 · 0 comments
Open

Deprecate GenericActor #311

mehdigmira opened this issue Oct 17, 2022 · 0 comments

Comments

@mehdigmira
Copy link

mehdigmira commented Oct 17, 2022

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 _actor

Example:

@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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant