Re: Future.get(Duration)?

2018-04-09 Thread Martin Buchholz
https://bugs.openjdk.java.net/browse/JDK-8201344

On Mon, Apr 9, 2018 at 3:49 PM, Steven Schlansker <
stevenschlans...@gmail.com> wrote:

> 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:
>
> @Value("my-timeout:PT10s")
> 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!
>
>


Future.get(Duration)?

2018-04-09 Thread Steven Schlansker
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:

@Value("my-timeout:PT10s")
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!