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

Feature. Support asyncio events #212

Open
jordic opened this issue Sep 7, 2020 · 5 comments
Open

Feature. Support asyncio events #212

jordic opened this issue Sep 7, 2020 · 5 comments

Comments

@jordic
Copy link

jordic commented Sep 7, 2020

We use zope.interface and the ZCA almost on every new project we start. The only peace we miss, it's being able to subscribe to async event handlers. We already do it, with a bit of inheritance but, does it make sense to provide a PR to being to support it on the default package?

@jamadden
Copy link
Member

jamadden commented Sep 7, 2020

Can you please clarify what you mean by "subscribe to async event handlers"?

@jordic
Copy link
Author

jordic commented Sep 8, 2020

For example: await notify(SomeEvent(obj)) and async def subscriber(event)

@jamadden
Copy link
Member

jamadden commented Sep 8, 2020

notify isn't defined here, that's over in zope.event. Because it wouldn't be backwards compatible, and because it still supports versions of Python that don't have async def/await I would imagine the odds of making notify into an async def function are extremely small.

As for async def subscriber(…):

zope.interface is connected to zope.event via zope.component, which uses the subscribers() API:

def dispatcher(event):
    zope.component.getSiteManager().subscribers(event, None)
zope.event.subscribers.append(dispatcher)

The subscription functions are defined to have no return value for the notify case. Without expensive runtime checking (which I would also imagine is a non-starter because this is extremely performance sensitive code), how is this loop supposed to deal with them?

def subscribers(self, objects, provided):
subscriptions = self.subscriptions([providedBy(o) for o in objects], provided)
if provided is None:
result = ()
for subscription in subscriptions:
subscription(*objects)
else:
result = []
for subscription in subscriptions:
subscriber = subscription(*objects)
if subscriber is not None:
result.append(subscriber)
return result

@mgedmin
Copy link
Member

mgedmin commented Sep 9, 2020

I'd say if you can create a PR that adds support for Python async in a backwards-compatible way, go for it!

@jordic
Copy link
Author

jordic commented Sep 10, 2020

What we are using, it's just and inherited adapter registry that supports async subscrbers. We use, zope.interface, standalone, without relaying on zope.event neither zope.component, because we don't support persistent registries neither context based registres. Addding something like this, will allow us to clean some code, that we are using everywhere.. (The AsyncAdapter registry)

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

3 participants