brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #816: Tasks code improvements - prep for better...
Date Thu, 28 Sep 2017 13:40:43 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/816#discussion_r141620123
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java ---
    @@ -269,6 +274,21 @@ public Boolean call() throws Exception {
             });
         }
     
    +    public <T> Repeater until(final Supplier<T> supplier, final Predicate<T>
exitCondition) {
    +        Preconditions.checkNotNull(supplier, "supplier must not be null");
    +        Preconditions.checkNotNull(exitCondition, "exitCondition must not be null");
    +        return until(new Callable<Boolean>() {
    +            @Override
    +            public Boolean call() throws Exception {
    +                return exitCondition.apply(supplier.get());
    +            }
    +            @Override
    +            public String toString() {
    +                return supplier.get()+" "+exitCondition.toString();
    --- End diff --
    
    many suppliers don't have a nice `toString()` and often when used (in tests) what we're
interested in is the value.  but i think you're right, this is potentially dangerous.  i've
added a last value cache and we now
    
        return ""+(lastValue.isPresent() ? lastValue.get() : supplier) + " " + exitCondition;



---

Mime
View raw message