In my application I have a switchIfEmpty pipeline that I'm having hard time to understand how it's working (or more specifically, how it's handing cancellation)
The purpose of the pipeline is to create a customer, and it's getting a customer object.
The first part of the pipeline is calling a reactiveMongoTemplate, searching for a customer document in my Database, based on the received customer id. Then, if it's not being found (i.e - received Mono.empty from the upstream), the switchIfEmpty calls a function that creates the customer.
I know that switchIfEmpty eagerly subscribes, and I'm not using solutions like Mono.defer in the pipeline, and yet, the customer isn't being created if the upstream find it.
Customer customer = new Customer("details of customer to be searched by");
findCustomer(customer) //calls a reactiveMongoTemplate find() function
.switchIfEmpty(saveCustomer(customer)); //calls a reactiveMongoTemplate save() function
This is the wanted behavior of course, but I just don't understand what happens in the background
Is a cancel() function being called? is the request being disposed of? how does mongo/reactiveMongoTemplate know what to revert?
Thanks for the answers!!!