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

Future.fromCompletableFuture should not block. #2115

Closed
2 tasks done
danieldietrich opened this issue Sep 27, 2017 · 1 comment
Closed
2 tasks done

Future.fromCompletableFuture should not block. #2115

danieldietrich opened this issue Sep 27, 2017 · 1 comment

Comments

@danieldietrich
Copy link
Contributor

danieldietrich commented Sep 27, 2017

Instead the wrapping Vavr Future needs to be completed using

  • Promise (for v0.9.2)
  • Future.join (for v1.0.0)
@danieldietrich
Copy link
Contributor Author

This test already works as expected with Vavr 0.9.2:

public class Xyz {

    public static void main(String[] args) throws Exception {

        final CompletableFuture<Integer> javaFuture = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(3000);
                return 1;
            } catch (InterruptedException e) {
                return 0;
            }
        });

        final Future<String> vavrFuture = Future.fromCompletableFuture(javaFuture).map(String::valueOf);

        System.out.println(vavrFuture);

        vavrFuture.forEach(System.out::println);

        Thread.sleep(5000);

        System.exit(0);

    }
}

Console output:

Future(?)
1

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