do not use java 8 CompletableFuture — use our Promise instead

CompletableFuture requires us to explicitly add catch handler to avoid error swallow — but our Promise automatically logs error if no catch handler
(cherry picked from commit 78c1814)
This commit is contained in:
Vladimir Krivosheev
2016-08-01 11:46:40 +02:00
parent fe7474ea1f
commit 640aec156b
3 changed files with 17 additions and 27 deletions
@@ -18,7 +18,6 @@ package com.intellij.profile.codeInspection
import com.intellij.codeInspection.InspectionProfile
import com.intellij.codeInspection.ex.InspectionProfileImpl
import com.intellij.codeInspection.ex.InspectionToolRegistrar
import com.intellij.concurrency.runAsync
import com.intellij.configurationStore.SchemeDataHolder
import com.intellij.configurationStore.digest
import com.intellij.openapi.Disposable
@@ -46,8 +45,10 @@ import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
import com.intellij.util.xmlb.XmlSerializer
import org.jdom.Element
import org.jetbrains.annotations.TestOnly
import org.jetbrains.concurrency.Promise
import org.jetbrains.concurrency.resolvedPromise
import org.jetbrains.concurrency.runAsync
import java.util.*
import java.util.concurrent.CompletableFuture
import java.util.function.Function
const val PROFILE = "profile"
@@ -80,7 +81,7 @@ class ProjectInspectionProfileManager(val project: Project,
private var state = State()
private val initialLoadSchemesFuture: CompletableFuture<*>
private val initialLoadSchemesFuture: Promise<*>
private val skipDefaultsSerializationFilter = object : SkipDefaultValuesSerializationFilters(State()) {
override fun accepts(accessor: Accessor, bean: Any, beanValue: Any?): Boolean {
@@ -129,7 +130,7 @@ class ProjectInspectionProfileManager(val project: Project,
val app = ApplicationManager.getApplication()
if (app.isUnitTestMode) {
initialLoadSchemesFuture = CompletableFuture.completedFuture(null)
initialLoadSchemesFuture = resolvedPromise()
}
else {
initialLoadSchemesFuture = runAsync { schemeManager.loadSchemes() }
@@ -175,7 +176,7 @@ class ProjectInspectionProfileManager(val project: Project,
private class ProjectInspectionProfileStartUpActivity : StartupActivity {
override fun runActivity(project: Project) {
getInstanceImpl(project).apply {
initialLoadSchemesFuture.thenRun {
initialLoadSchemesFuture.done {
currentProfile.initInspectionTools(project)
fireProfilesInitialized()
@@ -295,7 +296,7 @@ class ProjectInspectionProfileManager(val project: Project,
InspectionProfileImpl.getDefaultProfile(), null)
currentScheme.copyFrom(applicationProfileManager.currentProfile)
currentScheme.isProjectLevel = true
currentScheme.setName(PROJECT_DEFAULT_PROFILE_NAME)
currentScheme.name = PROJECT_DEFAULT_PROFILE_NAME
schemeManager.addScheme(currentScheme)
}
schemeManager.setCurrent(currentScheme, false)
@@ -18,6 +18,7 @@ package org.jetbrains.concurrency
import com.intellij.util.Consumer
import com.intellij.util.Function
import com.intellij.util.SmartList
import com.intellij.util.concurrency.AppExecutorUtil
import java.util.*
private val rejectedPromise = Promise.reject<Any?>("rejected")
@@ -113,4 +114,13 @@ inline fun <T> AsyncPromise<T>.compute(runnable: () -> T) {
if (!isRejected) {
setResult(result)
}
}
inline fun runAsync(crossinline runnable: () -> Unit): Promise<*> {
val promise = AsyncPromise<Any?>()
AppExecutorUtil.getAppExecutorService().execute {
promise.catchError { runnable() }
promise.setResult(null)
}
return promise
}
@@ -1,21 +0,0 @@
/*
* Copyright 2000-2016 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.
*/
package com.intellij.concurrency
import com.intellij.util.concurrency.AppExecutorUtil
import java.util.concurrent.CompletableFuture
inline fun runAsync(crossinline runnable: () -> Unit): CompletableFuture<Void> = CompletableFuture.runAsync(Runnable { runnable() }, AppExecutorUtil.getAppExecutorService())