FULFILLED -> SUCCEEDED

Because `fulfill` is not used - reduce glossary
This commit is contained in:
Vladimir Krivosheev
2018-05-15 15:25:10 +02:00
parent e86c216173
commit 75932a341f
11 changed files with 22 additions and 35 deletions
@@ -77,7 +77,7 @@ public class InternalPromiseUtil {
@NotNull
public Promise.State getState() {
return error == null ? Promise.State.FULFILLED : Promise.State.REJECTED;
return error == null ? Promise.State.SUCCEEDED : Promise.State.REJECTED;
}
public boolean isCancelled() {
@@ -22,13 +22,13 @@ import java.util.concurrent.TimeoutException;
*
* <ul>
* <li>pending: initial state, neither fulfilled nor rejected.</li>
* <li>fulfilled: meaning that the operation completed successfully.</li>
* <li>succeeded: meaning that the operation completed successfully.</li>
* <li>rejected: meaning that the operation failed.</li>
* </ul>
*/
public interface Promise<T> {
enum State {
PENDING, FULFILLED, REJECTED
PENDING, SUCCEEDED, REJECTED
}
/**
@@ -139,4 +139,8 @@ public interface Promise<T> {
default T blockingGet(int timeout) throws TimeoutException, ExecutionException {
return blockingGet(timeout, TimeUnit.MILLISECONDS);
}
default boolean isSucceeded() {
return getState() == State.SUCCEEDED;
}
}
@@ -207,7 +207,7 @@ public class PsiUtilBase extends PsiUtilCore implements PsiEditorUtil {
}
// We assume that data context from focus-based retrieval should success if performed from EDT.
Promise<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocusAsync();
if (asyncResult.getState() == Promise.State.FULFILLED) {
if (asyncResult.isSucceeded()) {
Editor editor = null;
try {
editor = CommonDataKeys.EDITOR.getData(asyncResult.blockingGet(-1));
@@ -139,7 +139,7 @@ class NonBlockingReadActionImpl<T> implements NonBlockingReadAction<T> {
void safeTransferToEdt(T result, Pair<ModalityState, Consumer<T>> edtFinish, ProgressIndicator indicator) {
if (Promises.isRejected(promise)) return;
Semaphore semaphore = new Semaphore(1);
ApplicationManager.getApplication().invokeLater(() -> {
if (checkObsolete()) {
@@ -147,13 +147,13 @@ class NonBlockingReadActionImpl<T> implements NonBlockingReadAction<T> {
return;
}
// complete the promise now to prevent write actions inside custom callback from cancelling it
// complete the promise now to prevent write actions inside custom callback from cancelling it
promise.setResult(result);
// now background thread may release its read lock, and we continue on EDT, invoking custom callback
semaphore.up();
if (Promises.isFulfilled(promise)) { // in case another thread managed to cancel it just before `setResult`
if (promise.isSucceeded()) { // in case another thread managed to cancel it just before `setResult`
edtFinish.second.accept(result);
}
}, edtFinish.first);
@@ -32,7 +32,7 @@ public abstract class AsyncValueLoader<T> {
public final T getResultIfFullFilled() {
Promise<T> result = ref.get();
try {
return (result != null && result.getState() == Promise.State.FULFILLED) ? result.blockingGet(0) : null;
return (result != null && result.isSucceeded()) ? result.blockingGet(0) : null;
}
catch (TimeoutException | ExecutionException e) {
return null;
@@ -87,7 +87,7 @@ public abstract class AsyncValueLoader<T> {
// if current promise is not processed, so, we don't need to check cache state
return promise;
}
else if (state == Promise.State.FULFILLED) {
else if (state == Promise.State.SUCCEEDED) {
//noinspection unchecked
if (!checkFreshness || isUpToDate()) {
return promise;
@@ -43,7 +43,7 @@ public abstract class PromiseManager<HOST, VALUE> {
public final boolean has(HOST host) {
Promise<VALUE> result = fieldUpdater.get(host);
return result != null && result.getState() == Promise.State.FULFILLED;
return result != null && result.isSucceeded();
}
@Nullable
@@ -76,7 +76,7 @@ public abstract class PromiseManager<HOST, VALUE> {
// if current promise is not processed, so, we don't need to check cache state
return promise;
}
else if (state == Promise.State.FULFILLED) {
else if (state == Promise.State.SUCCEEDED) {
//noinspection unchecked
try {
if (!checkFreshness || isUpToDate(host, promise.blockingGet(0))) {
@@ -412,7 +412,7 @@ public class AbstractTreeWalkerTest {
switch (walker.promise().getState()) {
case PENDING:
throw new IllegalStateException("not processed");
case FULFILLED:
case SUCCEEDED:
if (!error) break;
throw new IllegalStateException("not rejected");
case REJECTED:
@@ -23,7 +23,7 @@ open class AsyncPromise<T : Any?> : InternalPromiseUtil.BasePromise<T>(), Cancel
private val valueRef = AtomicReference<PromiseValue<T>?>(null)
override fun onSuccess(handler: Consumer<in T>): Promise<T> {
setHandler(doneRef, handler, State.FULFILLED)
setHandler(doneRef, handler, State.SUCCEEDED)
return this
}
@@ -93,7 +93,7 @@ open class AsyncPromise<T : Any?> : InternalPromiseUtil.BasePromise<T>(), Cancel
}
private fun addHandlers(done: Consumer<T>, rejected: Consumer<Throwable>) {
setHandler(doneRef, done, State.FULFILLED)
setHandler(doneRef, done, State.SUCCEEDED)
setHandler(rejectedRef, rejected, State.REJECTED)
}
@@ -226,7 +226,7 @@ open class AsyncPromise<T : Any?> : InternalPromiseUtil.BasePromise<T>(), Cancel
val currentState = value.state
if (currentState == targetState) {
@Suppress("UNCHECKED_CAST")
newConsumer.accept(if (currentState == State.FULFILLED) value.result as C_T else value.error as C_T)
newConsumer.accept(if (currentState == State.SUCCEEDED) value.result as C_T else value.error as C_T)
}
}
@@ -21,9 +21,6 @@ val Promise<*>.isRejected: Boolean
val Promise<*>.isPending: Boolean
get() = state == Promise.State.PENDING
val Promise<*>.isFulfilled: Boolean
get() = state == Promise.State.FULFILLED
private val REJECTED: Promise<*> by lazy { DonePromise<Any?>(InternalPromiseUtil.PromiseValue.createRejected(createError("rejected"))) }
@Suppress("UNCHECKED_CAST")
@@ -90,7 +90,7 @@ abstract class RemoteVmConnection<VmT : Vm> : VmConnection<VmT>() {
connectResult.handleThrowable(Consumer { result.setError(it) })
val channel = connectResult.channel
channel?.closeFuture()?.addListener {
if (result.isFulfilled) {
if (result.isSucceeded) {
close("Process disconnected unexpectedly", ConnectionStatus.DISCONNECTED)
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.maven.actions;
import com.intellij.openapi.module.EffectiveLanguageLevelUtil;
@@ -238,7 +224,7 @@ public class MavenProjectModelModifierTest extends MavenDomWithIndicesTestCase {
myProjectsManager.waitForArtifactsDownloadingCompletion();
performPostImportTasks();
myProjectsManager.performScheduledImportInTests();
assertSame(Promise.State.FULFILLED, result.getState());
assertSame(Promise.State.SUCCEEDED, result.getState());
}
private MavenProjectModelModifier getExtension() {