blob: 63186b99b197d771ead3bbba2a0b3bab09bf7f6e [file] [log] [blame]
package org.jetbrains.rpc;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.util.Function;
import org.jetbrains.annotations.Nullable;
final class CommandCallbackWithResponse<SUCCESS_RESPONSE, RESULT, TRANSFORMED_RESULT, ERROR_DETAILS>
extends CommandCallbackWithResponseBase<SUCCESS_RESPONSE, AsyncResult<TRANSFORMED_RESULT>, RESULT, ERROR_DETAILS> {
private final Function<RESULT, TRANSFORMED_RESULT> transform;
public CommandCallbackWithResponse(String methodName, Function<RESULT, TRANSFORMED_RESULT> transform, @Nullable ErrorConsumer<AsyncResult<TRANSFORMED_RESULT>, ERROR_DETAILS> errorConsumer) {
this(new AsyncResult<TRANSFORMED_RESULT>(), methodName, transform, errorConsumer);
}
public CommandCallbackWithResponse(AsyncResult<TRANSFORMED_RESULT> asyncResult, String methodName, Function<RESULT, TRANSFORMED_RESULT> transform, @Nullable ErrorConsumer<AsyncResult<TRANSFORMED_RESULT>, ERROR_DETAILS> errorConsumer) {
super(asyncResult, methodName, errorConsumer);
this.transform = transform;
}
@Override
protected void onSuccess(RESULT result) {
try {
callback.setDone(transform.fun(result));
}
catch (Throwable e) {
MessageManager.LOG.error(e);
}
}
}