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

Add toCompletableFuture for CompletableDeferredObject #4

Open
khoatruongdang opened this issue Oct 12, 2021 · 2 comments · May be fixed by #5
Open

Add toCompletableFuture for CompletableDeferredObject #4

khoatruongdang opened this issue Oct 12, 2021 · 2 comments · May be fixed by #5

Comments

@khoatruongdang
Copy link

We need Promise4j can work with other Async Processing Framework, at least with CompletableFuture of Java 8 core, so we must add toCompletableFuture for CompletableDeferredObject

@dungba88
Copy link
Owner

Here is one simple way to do it:

public static <T, E> CompletableFuture toCompletableFuture(Promise<T, E> promise) {
    var future = new CompletableFuture<T>();
    promise.done(future::complete).fail(future::completeExceptionally);
    return future;
}

@khoatruongdang
Copy link
Author

Thank for your help!!
I'm creating PR to add method in CompletableDeferredObject also:

public CompletableFuture<D> toCompletableFuture() {
        return future;
}

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

Successfully merging a pull request may close this issue.

2 participants