I have read from varying GitHub issues and other sources that using Promise.promise() is an anti-pattern. The recommendation is to convert the Context object to a ContextInternal and get a promise tied to the context. This is a little clunky especially since there is no official documentation that i have seen that says that using Vert.x internal classes was a good move, or at least this specific one to get a valid promise that is tied to the current context.
Could a maintainer/core contributor state here why it is an anti-pattern and the correct approach for callback based methods? This will help me greatly in evangelizing this within my organization. Promise.promise() is used extensively in our source code.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/868c67e6-2749-4ce9-bcdc-23ea7cfcb79an%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/9baba9b4-fc9f-4afe-8e6b-cbd405ef8fe2n%40googlegroups.com.
Thank you for providing an alternative approach to the sample database code. It is clear from that interaction that Promise.promise() is used quite a bit in the wild. It would REALLY help if it was emphasized more in the official documentation
, especially why it is not good to have Promise.promise()
I have put together a sample verticle below, forgive if it is too trivial. Is the "good" promise the best approach here? Why? What could happen if the bad promise is used?public class MainVerticle extends AbstractVerticle {
public Future<String> greet(String name) {
Promise<String> badPromise = Promise.promise(); // BAD
Promise<String> goodPromise = ((ContextInternal) context).promise(); // Good??
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/11af7bbe-3985-4d3e-89b1-96707f222a3an%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/f7aecfdf-0124-4f4b-a63e-e82ec43fc119n%40googlegroups.com.