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

Block returns null #1164

Open
yan-v opened this issue Aug 21, 2022 · 2 comments
Open

Block returns null #1164

yan-v opened this issue Aug 21, 2022 · 2 comments
Labels
question triaged Initial triage of issue has been performed

Comments

@yan-v
Copy link

yan-v commented Aug 21, 2022

Hi guys,
I need to perform several commands synchronously and return the response, but all commands after block return 'null', for instance:
CreateServiceInstanceResponse createServiceInstanceResponse = cloudFoundryOperations.services().createInstance(serviceInstanceRequestObj).cast(CreateServiceInstanceResponse.class).block();

As I see in CF, the command blocks and waits to Service Instance creation, but at the end the 'createServiceInstanceResponse' object is null.

Is this code incorrect or this is a bug?

Thank you in advance,
Yan

@dmikusa
Copy link
Contributor

dmikusa commented Aug 22, 2022

You don't typically want to use .block(), so I would suggest trying to asynchronously handle the problem and eliminate the need to block. If you have a Mono or Flux, there are methods on them to have things run in sequence. Like then() (and other then* methods). The first mono will run, then the next one will run. The flatMap() method is also quite handy as you can trigger some other action and flatten the results.

You mentioned Service creation, and we do have some helper utils in the tests which are an example of how you can create some of these objects in a sequence but not resort to blocking, see here. The service instance integration tests also have some examples, see here.

Hope that helps!

@dmikusa dmikusa added question triaged Initial triage of issue has been performed labels Aug 22, 2022
@yan-v
Copy link
Author

yan-v commented Aug 22, 2022

Hi, Daniel, thanks a lot for such detailed and prompt response!
I have a chain of some actions to do where each step failure not necessarily means a failure for my flow, i.e. if instance exists it is ok by me and i want to continue to service key creation, but want print the error.
using onError makes duplicate code. I expected to have return object to contain the error instead of Exception handling.

Thank you again!

Yan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question triaged Initial triage of issue has been performed
Projects
None yet
Development

No branches or pull requests

2 participants