Completable futures and promises

hi all,
so I have a java method like this:

@RolesAllowed("PrepCI")
	public CompletableFuture<RemoteOperStatus> reserveCI(CIDescriptor aCIDetails, @NonNull String aUserId, @NonNull String aUserName) {...}

vaadin translated it to

async function reserveCI_1(aCIDetails: CIDescriptor_1 | undefined, aUserId: string, aUserName: string, init?: EndpointRequestInit_1): Promise<unknown>

so I thought it has some support for it, but now that I tested it I think not :smiley:
should I just await the future in the backend then? what other option do I have?

thanks
Fernando

Especially if you run on Java 21 or above and have your server configured to use virtual threads, then it’s completely fine to just block until the result is available and then return that directly.

The other option is that you change the endpoint method to return a Flux and then use Mono.fromFuture to convert your CompletableFuture into something that you can return.

It would also be awesome if we could actually make it supported to directly return a CompletableFuture but we haven’t prioritized that yet.

2 Likes