Promise vs Future

574 views
Skip to first unread message

Roman Novikov

unread,
Oct 18, 2019, 11:41:29 AM10/18/19
to vert.x
Why promise was introduced in 3.8? It seems duplicate functionality with futures.

Julien Viet

unread,
Oct 19, 2019, 9:28:13 AM10/19/19
to vert.x
Hi,

in Vert.x 4 we use the promise/future and the Future interface removes the completion methods on it, so only Promise can be completed.

So a method returning a future creates Promise, keep a reference on the Promise to complete it and returns the Future from the method, e.g

default Future<Void> sendFile(String filename, long offset, long length) {
Promise<Void> promise = Promise.promise();
sendFile(filename, offset, length, promise);
return promise.future();
}
In 3.x the future can still be completed, to avoid breaking but it is deprecated.

Julien

On 18 Oct 2019, at 17:41, Roman Novikov <myst...@gmail.com> wrote:

Why promise was introduced in 3.8? It seems duplicate functionality with futures.

--
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/998ce325-40a6-48e9-86b1-ff6d31a1951f%40googlegroups.com.

Message has been deleted

Roman Novikov

unread,
Oct 19, 2019, 10:30:21 AM10/19/19
to vert.x
Hi Julien,

Now it's absolutely clear for me, thanks a lot!


On Saturday, October 19, 2019 at 4:28:13 PM UTC+3, Julien Viet wrote:
Hi,

in Vert.x 4 we use the promise/future and the Future interface removes the completion methods on it, so only Promise can be completed.

So a method returning a future creates Promise, keep a reference on the Promise to complete it and returns the Future from the method, e.g

default Future<Void> sendFile(String filename, long offset, long length) {
Promise<Void> promise = Promise.promise();
sendFile(filename, offset, length, promise);
return promise.future();
}
In 3.x the future can still be completed, to avoid breaking but it is deprecated.

Julien
On 18 Oct 2019, at 17:41, Roman Novikov <myst...@gmail.com> wrote:

Why promise was introduced in 3.8? It seems duplicate functionality with futures.

--
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 ve...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages