Skip to content

Deprecate GenericActor #311

Description

@mehdigmira

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions