cc.youchain.protocol.core.RemoteCall Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
YOUChain Common library in JAVA.
package cc.youchain.protocol.core;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import io.reactivex.Flowable;
import cc.youchain.utils.Async;
/**
* A common type for wrapping remote requests.
*
* @param Our return type.
*/
public class RemoteCall {
private Callable callable;
public RemoteCall(Callable callable) {
this.callable = callable;
}
/**
* Perform request synchronously.
*
* @return result of enclosed function
* @throws Exception if the function throws an exception
*/
public T send() throws Exception {
return callable.call();
}
/**
* Perform request asynchronously with a future.
*
* @return a future containing our function
*/
public CompletableFuture sendAsync() {
return Async.run(this::send);
}
/**
* Provide an flowable to emit result from our function.
*
* @return an flowable
*/
public Flowable flowable() {
return Flowable.fromCallable(this::send);
}
}