Mina Kh
Mina Kh

Reputation: 147

how to make spring web flux wait until specified condition met in server and then return the response

I'm a starter in Spring Web-Flux. i want to have a reactive service for example named isConfirmed and this service must wait until another service of my server is called for example named confirm. both services are located in my server and the first reactive service must wait until the second service (confirm) is called and then return the confirm message. i want no threads to be blocked in my server until the second service is called. like an observer pattern. is it possible with spring web flux?

update: can we have this feature while server using distributed cache?

Upvotes: 1

Views: 1986

Answers (1)

Zinc
Zinc

Reputation: 1144

I think you could use a CompletableFuture between your 2 services, something like that:

    CompletableFuture<String> future = new CompletableFuture<>();
    
    public Mono<String> isConfirmed() {
        return Mono.fromFuture(future);
    }
    
    public void confirm(String confirmation) {
        future.complete(confirmation);
    }

Upvotes: 2

Related Questions