io.proximax.async.AsyncCallbacks Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-chain-xipfs-sdk Show documentation
Show all versions of java-chain-xipfs-sdk Show documentation
Official ProximaX P2P Storage SDK Library in Java.
The newest version!
package io.proximax.async;
import java.util.function.Consumer;
/**
* This model class wraps the callbacks for asynchronous invocation
* @param the result type that this class will process
*/
public class AsyncCallbacks {
private final Consumer successCallback;
private final Consumer failureCallback;
public AsyncCallbacks(Consumer successCallback, Consumer failureCallback) {
this.successCallback = successCallback;
this.failureCallback = failureCallback;
}
/**
* Create instance of this callback
* @param successCallback the success callback
* @param failureCallback the failure callback
* @param the result type
* @return the async callback instance
*/
public static AsyncCallbacks create(Consumer successCallback, Consumer failureCallback) {
return new AsyncCallbacks(successCallback, failureCallback);
}
/**
* Invoke success callback with result
* @param result the result
*/
public void onSuccess(T result) {
if (successCallback != null) {
successCallback.accept(result);
}
}
/**
* Invoke failure callback with exception
* @param ex the exception
*/
public void onFailure(Throwable ex) {
if (failureCallback != null) {
failureCallback.accept(ex);
}
}
}