pymitter icon indicating copy to clipboard operation
pymitter copied to clipboard

Support async callable classes

Open Klavionik opened this issue 10 months ago • 0 comments

Hello! I'd like to use pymitter with async callable classes, like this.

class EventHandler:
    def __init__(self, dep1, dep2):  # Injected dependencies.
        self.dep1 = dep1
        self.dep2 = dep2

    async def __call__(self, arg):
        ...

ee.on("event", EventHandler(dep1, dep2))

It's not possible right now, due to the way pymitter checks if an event handler is async using asyncio.iscoroutinefunction. I've added another check that works with such callables. pyee supports this usecase, but sadly it lacks wildcard dispatching.

Klavionik avatar Apr 17 '24 23:04 Klavionik