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

Make the Future.join tryComplete function usable outside of the Future context #2126

Closed
danieldietrich opened this issue Oct 8, 2017 · 1 comment

Comments

@danieldietrich
Copy link
Contributor

We removed Promise in favor of Future.join(...) and made the tryComplete function accessible in a managed context only.

We have an example that might show the necessity of making the tryComplete function accessible from the outside (like Promise did before): Concurrent recursive function memoization.

The current API:

Future.join(tryComplete -> {
    final boolean isCompleted;
    if (ok()) {
         isCompleted = tryComplete.test(Try.success("ok"));
    } else {
         isCompleted = tryComplete.test(Try.failure(new Error()));
    }
    logger.log(isCompleted);
}

Current possibility to externalize tryComplete:

AtomicReference<CheckedConsumer<Predicate<Try<? extends T>>>> promise = ...;
Future<?> future = Future.join(tryComplete -> promise.set(tryComplete));

Now we take a look, if this is sufficient to re-implement #2096 (e.g. using a data structure instead of AtomicReference, it was only an example).

The solution to add more flexibility is that tryComplete returns the self reference to the underlying Future instead of a boolean complete status.

@danieldietrich danieldietrich added this to the vavr-1.0.0 milestone Oct 8, 2017
@danieldietrich danieldietrich changed the title Question: It is necessary to move the resolve out of the Future context? Make the Future.join tryComplete function usable outside of the Future context? Oct 8, 2017
@danieldietrich danieldietrich changed the title Make the Future.join tryComplete function usable outside of the Future context? Make the Future.join tryComplete function usable outside of the Future context Oct 8, 2017
@danieldietrich
Copy link
Contributor Author

Our Future implementation will be dropped. There will be no Vavr 1.0 module vavr-concurrent.

Reason: Implementing our own concurrency library is too error-prone, concurrency is a hard problem. There are many(!) alternatives, first of all Java's native CompletableFuture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant