-
Notifications
You must be signed in to change notification settings - Fork 18
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: add async methods #383
feat: add async methods #383
Conversation
1fa133a
to
dcb83ac
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #383 +/- ##
==========================================
- Coverage 97.41% 95.16% -2.25%
==========================================
Files 26 27 +1
Lines 1239 1511 +272
==========================================
+ Hits 1207 1438 +231
- Misses 32 73 +41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
59f26c1
to
de92f5d
Compare
Nice work @leohoare, thanks for putting this out! It's a great starting point for discussing async support in the Python SDK! As I was reviewing it, a couple of things came to my mind, and I want to hear your thoughts:
client = openfeature_api.get_async_client()
await client.get_boolean_value("flag-key", False) This way you won't accidentally call a sync method inside async code, as long as you grabbed the correct client first.
|
Yeah, I agree. Splitting the clients into async / sync would be a cleaner division. Edit: The more I look at it, I somewhat more prefer the _async suffix, but either pattern is good. Saying that, in our case, It'd be a bit messy to force people to implement the _sync methods whenever they want to use the _async.
If we're splitting the clients, I'd lean towards making all hooks async on that client. |
Can you elaborate a bit more on this? I'm leaning a bit towards splitting the two, particularly because they may involve different initialization/shutdown routines due to the different clients being used, but I want to make sure I understand the benefits and tradeoffs from the other side too. |
I more mean as a style / how it'd used, when a function has the _async suffix you're reminded to await it and handle it appropriately. Where as the AsyncClient requires you to know upfront that all functions are async.
For our use case given initialization/shutdown/hooks may want to be handled differently, so having separate clients is looking more appropriate. Another advantage is if someone wants to use async methods, we shouldn't force them to implement to the sync methods. Extending and only forcing 1 of the 2 methods would be messy. |
0fb851e
to
b2e84cc
Compare
Note, the current code is not ready and needs more unit tests / evaluation for this amount of code change. What do you think about the change though? |
cadd4ed
to
9275136
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the async client is a good idea. Just for my own understanding, the async hooks can be used as a drop in a replacement anywhere a hook current is supported, right? If that's the case, I'm fine with the approach. I just want to make sure hook support isn't fragmented by this change.
Apologies, been a bit busy the last few days and will pick off chunks when I get time. Things still TODO:
The current behaviour is:
Do we want the AsyncClient to support both sync and async hooks? |
184c036
to
272d659
Compare
Signed-off-by: leohoare <leo@insight.co>
Signed-off-by: leohoare <leo@insight.co>
Signed-off-by: leohoare <leo@insight.co>
Signed-off-by: leohoare <leo@insight.co>
Signed-off-by: leohoare <leo@insight.co>
Ideally, we would like to support providers and hooks like the standard OTel one without duplicating implementations, but I'm not sure what's the best approach for that. @leohoare are you on the #openfeature-python CNCF Slack channel? Would you mind joining? |
I'll have a play around with open telemetry hooks and the confidence provider and how they interact. Agree ideally we should support this hook out the box and it should support sync hooks. Perhaps a simpler PR for the first version would just be introducing async methods to the flag resolution and not consider async hooks. Yep I've joined the slack channel. |
Going to close this PR in favour of #385. |
This PR
Adds the ability for open feature providers to use async methods
Related Issues
#284
Notes
Just confirming the approach / POC for how this would work.
Follow-up Tasks
How to test
TODO