mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify — use Promise
This commit is contained in:
@@ -132,4 +132,19 @@ public abstract class Promise<T> {
|
||||
public abstract boolean isProcessed();
|
||||
|
||||
public abstract boolean isRejected();
|
||||
|
||||
public final void notify(@NotNull final AsyncResult<T> result) {
|
||||
done(new Consumer<T>() {
|
||||
@Override
|
||||
public void consume(T t) {
|
||||
result.setDone(t);
|
||||
}
|
||||
});
|
||||
rejected(new Consumer<String>() {
|
||||
@Override
|
||||
public void consume(String error) {
|
||||
result.reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public abstract class DeclarativeScope<VALUE_LOADER extends ValueManager> extend
|
||||
|
||||
@Override
|
||||
public void load(@NotNull DeclarativeScope host, @NotNull AsyncResult<List<Variable>> result) {
|
||||
host.loadVariables(result);
|
||||
host.loadVariables().notify(result);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -41,27 +41,23 @@ public abstract class DeclarativeScope<VALUE_LOADER extends ValueManager> extend
|
||||
/**
|
||||
* You must call {@link #updateCacheStamp()} when data loaded
|
||||
*/
|
||||
protected abstract void loadVariables(@NotNull AsyncResult<List<? extends Variable>> result);
|
||||
@NotNull
|
||||
protected abstract Promise<List<Variable>> loadVariables();
|
||||
|
||||
protected final void updateCacheStamp() {
|
||||
cacheStamp = valueManager.getCacheStamp();
|
||||
}
|
||||
|
||||
protected final void loadScopeObjectProperties(@NotNull ObjectValue value, @NotNull final AsyncResult<List<? extends Variable>> result) {
|
||||
if (valueManager.rejectIfObsolete(result)) {
|
||||
return;
|
||||
@NotNull
|
||||
protected final Promise<List<Variable>> loadScopeObjectProperties(@NotNull ObjectValue value) {
|
||||
if (valueManager.isObsolete()) {
|
||||
return ValueManager.reject();
|
||||
}
|
||||
|
||||
value.getProperties().done(new Consumer<List<Variable>>() {
|
||||
return value.getProperties().done(new Consumer<List<Variable>>() {
|
||||
@Override
|
||||
public void consume(List<Variable> variables) {
|
||||
updateCacheStamp();
|
||||
result.setDone(variables);
|
||||
}
|
||||
}).rejected(new Consumer<String>() {
|
||||
@Override
|
||||
public void consume(String error) {
|
||||
result.reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.util.CommonProcessors;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.debugger.values.FunctionValue;
|
||||
|
||||
public interface ScriptManager {
|
||||
@@ -22,7 +23,7 @@ public interface ScriptManager {
|
||||
* Demands that script text should be replaced with a new one if possible. VM may get resumed after this command
|
||||
*/
|
||||
@NotNull
|
||||
AsyncResult<?> setSourceOnRemote(@NotNull Script script, @NotNull CharSequence newSource, boolean preview);
|
||||
Promise<?> setSourceOnRemote(@NotNull Script script, @NotNull CharSequence newSource, boolean preview);
|
||||
|
||||
void forEachScript(@NotNull Processor<Script> scriptProcessor);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.debugger.values;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.concurrency.ConsumerRunnable;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -50,4 +51,9 @@ public abstract class ValueManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> Promise<T> reject() {
|
||||
return Promise.reject("Obsolete context");
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,6 @@ public interface CommandSender<ERROR_DETAILS> {
|
||||
|
||||
<RESULT> Promise<RESULT> send(@NotNull RequestWithResponse<RESULT> message);
|
||||
|
||||
<RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull RequestWithResponse message, @NotNull Function<RESULT, TRANSFORMED_RESULT> transform);
|
||||
|
||||
<RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull RequestWithResponse message,
|
||||
@NotNull Function<RESULT, TRANSFORMED_RESULT> transform,
|
||||
@Nullable ErrorConsumer<AsyncResult<TRANSFORMED_RESULT>, ERROR_DETAILS> errorConsumer);
|
||||
|
||||
@@ -21,11 +21,6 @@ public abstract class CommandSenderBase<SUCCESS_RESPONSE, ERROR_DETAILS> impleme
|
||||
return callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull RequestWithResponse message, @NotNull Function<RESULT, TRANSFORMED_RESULT> transform) {
|
||||
return send(message, transform, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <RESULT> Promise<RESULT> send(@NotNull RequestWithResponse<RESULT> request) {
|
||||
PromiseWrapper<SUCCESS_RESPONSE, RESULT, ERROR_DETAILS> callback = new PromiseWrapper<SUCCESS_RESPONSE, RESULT, ERROR_DETAILS>(request.getMethodName());
|
||||
|
||||
Reference in New Issue
Block a user