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

api: Add consume_first for convenience #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on May 3, 2019

  1. 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())
        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 <vfeenstr@redhat.com>
    vinzenz committed May 3, 2019
    Configuration menu
    Copy the full SHA
    59b4bea View commit details
    Browse the repository at this point in the history