esbtools / event-handler

Notification in, document out.
GNU General Public License v3.0
3 stars 6 forks source link

Lazy future transforms are not called if the future is already completed #68

Open alechenninger opened 8 years ago

alechenninger commented 8 years ago

Hasn't been a problem in practice by nature of their laziness, but this should be fixed. Shouldn't be hard.

dcrissman commented 7 years ago

Is this because if (isDone()) return; happens first in the complete methods on LazyTransformingFuture and LazyTransformableFuture?

alechenninger commented 7 years ago

No, if you look here:

@Override
public <V> TransformableFuture<V> transformSync(FutureTransform<U, V> futureTransform) {
    LazyTransformingFuture<U, V> future =
            new LazyTransformingFuture<>(futureTransform, completer);
    next.add(future);
    return future;
}

All this does is add it to the list of next futures to complete once we have a result.

What if we already have a result? The newly added futures will never be completed.

So in this method, we need to atomically check if the future is already completed, and in that case just complete the passed in future immediately, synchronously. Otherwise, add it to next.