-
Notifications
You must be signed in to change notification settings - Fork 70
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
api: Add consume_first for convenience #502
base: main
Are you sure you want to change the base?
Conversation
665a860
to
cbcdd5a
Compare
A lot of actors are expecting only one type and are using next to retrieve the value. This patch introduces a convenience function that is simplifying the usage for actors that have a need for this. Additionally it covers some gotchas that are mostly not handled, mainly if there is no message available then an empty tuple is returned that is not iterable by next. Usage example: -------------- ``` from leapp.libraries.stdlib import api from leapp.models import SomeModel def some_function_previously(): value = next(api.consume(SomeModel), None) value_other = next(api.consume(SomeModel), SomeModel()) value_different = next(api.consume(SomeModel), 'yadda') def some_function_now(): value = api.consume_first(SomeModel) value_other api.consume_first_default(SomeModel) value_different = api.consume_first(SomeModel, 'yadda') ``` Signed-off-by: Vinzenz Feenstra <[email protected]>
Wondering if it makes sense to check if there's actually more messages and maybe emit a log message if there is, i.e. |
That'd be something like expect_one or so, no? |
Yeah, for me |
+1 for Edit: or True/False paramter can be added. |
Thank you for contributing to the Leapp project!Please note that every PR needs to comply with the Leapp Guidelines, pass tests and linter checks before it can be merged. If you want to re-run tests or request review, you can use following commands as a comment:
|
That's a nice to have thing, maybe we could revive it? |
@fernflower I think we could do ~ cabal mtg after we finish everything around the current release to discuss extension of the provided API. or we could create something somewhere where we could discuss it. I mean, not just this, but in general from our experience, whether we could identify more functions we that could make sense to put into the library. |
A lot of actors are expecting only one type and are using next to
retrieve the value. This patch introduces a convenience function that is
simplifying the usage for actors that have a need for this.
Additionally it covers some gotchas that are mostly not handled, mainly
if there is no message available then an empty tuple is returned that is
not iterable by next.
Usage example:
Signed-off-by: Vinzenz Feenstra [email protected]