[Gradle] KotlinPluginLifecycle: requiredStage: Wait for stage if necessary
^KT-58676 In Progress
This commit is contained in:
committed by
Space Team
parent
1a143ec1a2
commit
b9a8f6dce2
+2
@@ -191,8 +191,10 @@ internal suspend fun <T : Any> Property<T>.awaitFinalValue(): T? {
|
||||
* See also [withRestrictedStages]
|
||||
*
|
||||
* Will ensure that the given [block] can only execute in the given [stage]
|
||||
* Will wait for the given [stage] if not arrived yet
|
||||
*/
|
||||
internal suspend fun <T> requiredStage(stage: Stage, block: suspend () -> T): T {
|
||||
if (currentKotlinPluginLifecycle().stage < stage) stage.await()
|
||||
return withRestrictedStages(hashSetOf(stage), block)
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -458,6 +458,16 @@ class KotlinPluginLifecycleTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - requireStage`() = project.runLifecycleAwareTest {
|
||||
launch {
|
||||
requiredStage(AfterFinaliseDsl) {
|
||||
assertEquals(AfterFinaliseDsl, stage)
|
||||
assertFailsWith<IllegalLifecycleException> { AfterFinaliseDsl.nextOrThrow.await() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - withRestrictedStages`() = project.runLifecycleAwareTest {
|
||||
launch {
|
||||
|
||||
Reference in New Issue
Block a user