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

feat: support coroutine functions #346

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Dec 20, 2024

fixes #345

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (6db5219) to head (4fb4ef8).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #346   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         2095      2101    +6     
=========================================
+ Hits          2095      2101    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@davidbrochart
Copy link

Thanks for the quick PR @tlambert03!
In #345 you mentioned that:

psygnal itself has no concept of an event loop (it's a "bring-your-own-event-loop" library)

But this PR currently assumes that the event loop is asyncio. However Trio and AnyIO are very popular, so I'm wondering how we could support them and really be event-loop agnostic.

@davidbrochart
Copy link

Because structured concurrency always needs a task group in order to launch tasks, I think it's better to not support async callbacks in psygnal. One can just use a sync callback, and have the async logic in the user code where the new value is put synchronously in a stream, and a background task gets the values from the stream asynchronously. That way the user can launch this background task in the appropriate task group.

@tlambert03
Copy link
Member Author

Thanks for your input!

I think it's better to not support async callbacks in psygnal. One can just use a sync callback, and have the async logic in the user code where the new value is put synchronously in a stream, and a background task gets the values from the stream asynchronously.

Are you sure? I'm definitely happy to do whatever we can here to make using coroutines in psygnal easier. That could include supporting auto detection of asyncio, trio, or anyio.

I don't have a ton of personal experience with async/await, so would happily take advice and implement whatever folks suggest.
At the very least we could add some better documentation explaining/showing the strategy you mentioned for using a sync function to put a task in a stream.

And if there are conveniences we could add around that pattern, that's fine too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Connect signal to async callback
2 participants