
org.smallibs.concurrent.promise.impl.FlatMappedFuture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hpas Show documentation
Show all versions of hpas Show documentation
Functional ADT And Asynchronous library in Java
/*
* HPAS
* https://github.com/d-plaindoux/hpas
*
* Copyright (c) 2016-2017 Didier Plaindoux
* Licensed under the LGPL2 license.
*/
package org.smallibs.concurrent.promise.impl;
import org.smallibs.concurrent.promise.Promise;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
class FlatMappedFuture implements Future {
private final Future future;
private final Function super T, Promise> function;
FlatMappedFuture(Future future, Function super T, Promise> function) {
this.future = future;
this.function = function;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return this.future.cancel(mayInterruptIfRunning);
}
@Override
public boolean isCancelled() {
return this.future.isCancelled();
}
@Override
public boolean isDone() {
return this.future.isDone();
}
@Override
public R get() throws InterruptedException, ExecutionException {
return this.function.apply(this.future.get()).getFuture().get();
}
@Override
public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return this.function.apply(this.future.get(timeout, unit)).getFuture().get(timeout, unit);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy