-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: Add consume_first for convenience
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()) def some_function_now(): value = api.consume_first(SomeModel) value_other api.consume_first(SomeModel, default=SomeModel()) ``` Signed-off-by: Vinzenz Feenstra <[email protected]>
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters