Steven Schlansker stevenschlansker at gmail.com
Mon Apr 9 22:49:32 UTC 2018

Hi core-libs-dev,

Future.get(int, TimeUnit) is great, it allows you to put a timeout.

Duration is great, it's a common way to cart a duration around, and some frameworks can parse it for you, say
you have an injector (Spring in this case) that can handle:

Duration timeout;

Now, you might obviously try to write:

myFuture.get(timeout); // ARGH

only to find out that instead you have to do some convoluted construction like

myFuture.get(timeout.toMillis(), TimeUnit.MILLISECONDS); // :(

How about a super simple added method to Future?

default T get(Duration timeout) throws TimeoutException {
    return get(timeout.toMillis(), TimeUnit.MILLISECONDS); // maybe this should handle nanos, but you get the idea

Thanks for considering!

More information about the core-libs-dev mailing list