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

Add a send_async method to the Signal #76

Merged
merged 1 commit into from Jan 24, 2023
Merged

Conversation

pgjones
Copy link
Member

@pgjones pgjones commented Jul 23, 2022

This allows for signals to send to coroutine receivers by awaiting
them. The _async_wrapper and _sync_wrapper allows for conversion of
sync and async receivers as required if defined. If not defined a
runtime error is raised.

The wrappers are used to avoid any direct tie into asyncio, trio,
greenbacks, asgiref, or other specific async implementation.

@pgjones pgjones force-pushed the main branch 3 times, most recently from 042b329 to f2610a4 Compare July 23, 2022 11:27
@pgjones
Copy link
Member Author

pgjones commented Jul 23, 2022

Note that if async coroutines are connected to any signal's receiver_connected or receiver_disconnected there will be a runtime error. I think this is acceptable.

@DonDebonair
Copy link

I saw that previous code to supprt async was reverted. Can we merge this one in and get a release soon?

@davidism
Copy link
Member

davidism commented Aug 4, 2022

We'll merge this when we're ready and have time. Async as it works in a hybrid environment, and how it will work with Flask and quart, is a very complex question.

@leandrorebelo

This comment was marked as off-topic.

blinker/base.py Outdated Show resolved Hide resolved
@pgjones
Copy link
Member Author

pgjones commented Jan 22, 2023

@Secrus what do you make of this?

Copy link
Member

@Secrus Secrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surely needs a proper documentation entry.

requirements/tests.txt Show resolved Hide resolved
src/blinker/_utilities.py Show resolved Hide resolved
src/blinker/base.py Show resolved Hide resolved
@pgjones
Copy link
Member Author

pgjones commented Jan 23, 2023

I've added documentation

Copy link
Member

@Secrus Secrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase with main, other than that, LGTM.

This allows for signals to send to coroutine receivers by awaiting
them. The _async_wrapper and _sync_wrapper allows for conversion of
sync and async receivers as required if defined. If not defined a
runtime error is raised.

The wrappers are used to avoid any direct tie into asyncio, trio,
greenbacks, asgiref, or other specific async implementation.
@djsilcock
Copy link

djsilcock commented Mar 22, 2023

Just as an observation on the principle of least surprise, I would have intuitively expected await some_signal.send_async() to run the handlers concurrently, rather than sequentially - the concurrent behaviour would require something like:

def wrapper(fn):
      @wraps(fn)
      def handler(sender,**kwargs):
          return asyncio.create_task(fn(sender,**kwargs)
      return handler
res=[(rec,await result if asyncio.isfuture(result) else result) for rec,result in some_signal.send(_async_wrapper=wrapper)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants