Future.get(Duration)?
Martin Buchholz
martinrb at google.com
Mon Apr 9 22:58:18 UTC 2018
https://bugs.openjdk.java.net/browse/JDK-8201344
On Mon, Apr 9, 2018 at 3:49 PM, Steven Schlansker <
stevenschlansker at 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!
>
>
More information about the core-libs-dev
mailing list