[Gradle] CompletableFuture: Add 'isCompleted' API
^KT-60441 Verification Pending
This commit is contained in:
committed by
Space Team
parent
0feecebc07
commit
a49db89024
+4
@@ -53,6 +53,7 @@ internal interface LenientFuture<T> : Future<T> {
|
||||
}
|
||||
|
||||
internal interface CompletableFuture<T> : Future<T> {
|
||||
val isCompleted: Boolean
|
||||
fun complete(value: T)
|
||||
}
|
||||
|
||||
@@ -112,6 +113,9 @@ private class FutureImpl<T>(
|
||||
) : CompletableFuture<T>, Serializable {
|
||||
fun completeWith(result: Result<T>) = deferred.completeWith(result)
|
||||
|
||||
override val isCompleted: Boolean
|
||||
get() = deferred.isCompleted
|
||||
|
||||
override fun complete(value: T) {
|
||||
deferred.complete(value)
|
||||
}
|
||||
|
||||
+18
-3
@@ -20,9 +20,7 @@ import org.jetbrains.kotlin.gradle.utils.*
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.*
|
||||
|
||||
class FutureTest {
|
||||
|
||||
@@ -164,4 +162,21 @@ class FutureTest {
|
||||
assertFailsWith<IllegalLifecycleException> { future.getOrThrow() }
|
||||
future.await()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - future isCompleted`() = project.runLifecycleAwareTest {
|
||||
val future = CompletableFuture<Unit>()
|
||||
assertFalse(future.isCompleted)
|
||||
|
||||
launchInStage(KotlinPluginLifecycle.Stage.AfterFinaliseDsl) {
|
||||
assertFalse(future.isCompleted)
|
||||
future.complete(Unit)
|
||||
assertTrue(future.isCompleted)
|
||||
}
|
||||
|
||||
launch {
|
||||
future.await()
|
||||
assertTrue(future.isCompleted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user