redhat-helloworld-msa / aloha

Microservice using Vert.x
Apache License 2.0
11 stars 65 forks source link

Invoke the bonjour service in an asynchronous non-blocking fashion #1

Closed cescoffier closed 8 years ago

cescoffier commented 8 years ago

This way is compliant with Vert.x.

Notice that I had to change the service interface to use an Observable as it's the only way to be async and non-blocking.

Another approach (that does not require the service change) would be to use:

vertx.<List<String>>executeBlocking(
  future -> {
     // Blocking, but running on a worker thread
     future.complete(getTheResultingList());
  },
  ar -> {
   // Back on the event loop, can write in the response
  }

Both approaches have pros and cons.

rafabene commented 8 years ago

Hi @cescoffier . Thanks for the PR. I'll merge it soon.

cescoffier commented 8 years ago

@rafabene Let me know which approach you would prefer:

I can provide the second PR if you want.

rafabene commented 8 years ago

My preference would be for the one with the simplest code. I don't want the attendees to think that it's too hard or too complex when they see the code. Do you mind to send the second PR so we could compare?

Thanks so much for your support.

cescoffier commented 8 years ago

No problm, will open another PR today or tomorrow morning.

rafabene commented 8 years ago

Closing this since we decided to go with approach #2