Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Apr 23, 2024
1 parent 68ab187 commit d10d570
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit
* @see allOfCffu
* @see allOfCompletableFutureVoid
*/
fun <T> Collection<CompletableFuture<T>>.allOfCompletableFuture(): CompletableFuture<List<T>> =
fun <T> Collection<CompletableFuture<out T>>.allOfCompletableFuture(): CompletableFuture<List<T>> =
CompletableFutureUtils.allResultsOf(*this.toTypedArray())

/**
Expand All @@ -57,7 +57,7 @@ fun <T> Collection<CompletableFuture<T>>.allOfCompletableFuture(): CompletableFu
* @see allOfCffu
* @see allOfCompletableFutureVoid
*/
fun <T> Array<out CompletableFuture<T>>.allOfCompletableFuture(): CompletableFuture<List<T>> =
fun <T> Array<out CompletableFuture<out T>>.allOfCompletableFuture(): CompletableFuture<List<T>> =
CompletableFutureUtils.allResultsOf(*this)

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ fun Array<out CompletableFuture<*>>.allOfCompletableFutureVoid(): CompletableFut
* @see allOfFastFailCffu
* @see allOfFastFailCompletableFutureVoid
*/
fun <T> Collection<CompletableFuture<T>>.allOfFastFailCompletableFuture(): CompletableFuture<List<T>> =
fun <T> Collection<CompletableFuture<out T>>.allOfFastFailCompletableFuture(): CompletableFuture<List<T>> =
CompletableFutureUtils.allResultsOfFastFail(*this.toTypedArray())

/**
Expand All @@ -137,7 +137,7 @@ fun <T> Collection<CompletableFuture<T>>.allOfFastFailCompletableFuture(): Compl
* @see allOfFastFailCffu
* @see allOfFastFailCompletableFutureVoid
*/
fun <T> Array<out CompletableFuture<T>>.allOfFastFailCompletableFuture(): CompletableFuture<List<T>> =
fun <T> Array<out CompletableFuture<out T>>.allOfFastFailCompletableFuture(): CompletableFuture<List<T>> =
CompletableFutureUtils.allResultsOfFastFail(*this)

/**
Expand Down Expand Up @@ -185,7 +185,6 @@ fun Array<out CompletableFuture<*>>.allOfFastFailCompletableFutureVoid(): Comple
// - anyOfCompletableFuture
// - anyOfCompletableFutureAny
// - anyOfSuccessCompletableFuture
// - anyOfSuccessCompletableFutureAny
////////////////////////////////////////

/**
Expand All @@ -195,13 +194,11 @@ fun Array<out CompletableFuture<*>>.allOfFastFailCompletableFutureVoid(): Comple
* with a CompletionException holding this exception as its cause.
* If no CompletableFutures are provided, returns an incomplete CompletableFuture.
*
* Same as [anyOfCompletableFutureAny], but return result type is specified type instead of type `Any`.
* Same as [CompletableFutureUtils.anyOf], providing this method is convenient for method chaining.
*
* @see anyOfCffu
* @see anyOfCompletableFutureAny
*/
fun <T> Collection<CompletableFuture<T>>.anyOfCompletableFuture(): CompletableFuture<T> =
fun <T> Collection<CompletableFuture<out T>>.anyOfCompletableFuture(): CompletableFuture<T> =
CompletableFutureUtils.anyOf(*this.toTypedArray())

/**
Expand All @@ -211,49 +208,13 @@ fun <T> Collection<CompletableFuture<T>>.anyOfCompletableFuture(): CompletableFu
* with a CompletionException holding this exception as its cause.
* If no CompletableFutures are provided, returns an incomplete CompletableFuture.
*
* Same as [anyOfCompletableFutureAny], but return result type is specified type instead of type `Any`.
* Same as [CompletableFutureUtils.anyOf], providing this method is convenient for method chaining.
*
* @see anyOfCffu
* @see anyOfCompletableFutureAny
*/
fun <T> Array<out CompletableFuture<T>>.anyOfCompletableFuture(): CompletableFuture<T> =
fun <T> Array<out CompletableFuture<out T>>.anyOfCompletableFuture(): CompletableFuture<T> =
CompletableFutureUtils.anyOf(*this)

/**
* Returns a new CompletableFuture that is completed
* when any of the given CompletableFutures complete, with the same result.
* Otherwise, if it completed exceptionally, the returned CompletableFuture also does so,
* with a CompletionException holding this exception as its cause.
* If no CompletableFutures are provided, returns an incomplete CompletableFuture.
*
* Same as [CompletableFuture.anyOf], providing this method is convenient for method chaining.
*
* @see anyOfCffu
* @see anyOfCffuAny
* @see anyOfCompletableFuture
* @see CompletableFuture.anyOf
*/
fun Collection<CompletableFuture<*>>.anyOfCompletableFutureAny(): CompletableFuture<Any> =
CompletableFuture.anyOf(*this.toTypedArray())

/**
* Returns a new CompletableFuture that is completed
* when any of the given CompletableFutures complete, with the same result.
* Otherwise, if it completed exceptionally, the returned CompletableFuture also does so,
* with a CompletionException holding this exception as its cause.
* If no CompletableFutures are provided, returns an incomplete CompletableFuture.
*
* Same as [CompletableFuture.anyOf], providing this method is convenient for method chaining.
*
* @see anyOfCffu
* @see anyOfCffuAny
* @see anyOfCompletableFuture
* @see CompletableFuture.anyOf
*/
fun Array<out CompletableFuture<*>>.anyOfCompletableFutureAny(): CompletableFuture<Any> =
CompletableFuture.anyOf(*this)

/**
* Returns a new CompletableFuture that is successful when any of the given CompletableFutures success,
* with the same result. Otherwise, all the given CompletableFutures complete exceptionally,
Expand All @@ -262,13 +223,12 @@ fun Array<out CompletableFuture<*>>.anyOfCompletableFutureAny(): CompletableFutu
* returns a new CompletableFuture that is already completed exceptionally with a CompletionException
* holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause.
*
* Same as [anyOfSuccessCompletableFutureAny], but return result type is specified type instead of type `Any`.
* Same as [CompletableFutureUtils.anyOfSuccess], providing this method is convenient for method chaining.
*
* @see anyOfCompletableFuture
* @see CompletableFutureUtils.anyOfSuccess
*/
fun <T> Collection<CompletableFuture<T>>.anyOfSuccessCompletableFuture(): CompletableFuture<T> =
fun <T> Collection<CompletableFuture<out T>>.anyOfSuccessCompletableFuture(): CompletableFuture<T> =
CompletableFutureUtils.anyOfSuccess(*this.toTypedArray())

/**
Expand All @@ -279,47 +239,12 @@ fun <T> Collection<CompletableFuture<T>>.anyOfSuccessCompletableFuture(): Comple
* returns a new CompletableFuture that is already completed exceptionally with a CompletionException
* holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause.
*
* Same as [anyOfSuccessCompletableFutureAny], but return result type is specified type instead of type `Any`.
* Same as [CompletableFutureUtils.anyOfSuccess], providing this method is convenient for method chaining.
*
* @see anyOfCompletableFuture
* @see CompletableFutureUtils.anyOfSuccess
*/
fun <T> Array<out CompletableFuture<T>>.anyOfSuccessCompletableFuture(): CompletableFuture<T> =
CompletableFutureUtils.anyOfSuccess(*this)

/**
* Returns a new CompletableFuture that is successful when any of the given CompletableFutures success,
* with the same result. Otherwise, all the given CompletableFutures complete exceptionally,
* the returned CompletableFuture also does so, with a CompletionException holding
* an exception from any of the given CompletableFutures as its cause. If no CompletableFutures are provided,
* returns a new CompletableFuture that is already completed exceptionally with a CompletionException
* holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause.
*
* Same as [CompletableFutureUtils.anyOfSuccess], providing this method is convenient for method chaining.
*
* @see anyOfSuccessCffu
* @see anyOfCompletableFuture
* @see CompletableFutureUtils.anyOfSuccess
*/
fun Collection<CompletableFuture<*>>.anyOfSuccessCompletableFutureAny(): CompletableFuture<Any> =
CompletableFutureUtils.anyOfSuccess(*this.toTypedArray())

/**
* Returns a new CompletableFuture that is successful when any of the given CompletableFutures success,
* with the same result. Otherwise, all the given CompletableFutures complete exceptionally,
* the returned CompletableFuture also does so, with a CompletionException holding
* an exception CompletableFuture any of the given CompletableFutures as its cause. If no CompletableFutures are provided,
* returns a new Cffu that is already completed exceptionally with a CompletionException
* holding a [NoCfsProvidedException][io.foldright.cffu.NoCfsProvidedException] as its cause.
*
* Same as [CompletableFutureUtils.anyOfSuccess], providing this method is convenient for method chaining.
*
* @see anyOfSuccessCffu
* @see anyOfCompletableFuture
* @see CompletableFutureUtils.anyOfSuccess
*/
fun Array<out CompletableFuture<*>>.anyOfSuccessCompletableFutureAny(): CompletableFuture<Any> =
fun <T> Array<out CompletableFuture<out T>>.anyOfSuccessCompletableFuture(): CompletableFuture<T> =
CompletableFutureUtils.anyOfSuccess(*this)

////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ class CompletableFutureExtensionsTest : FunSpec({
CompletableFuture<String>(),
CompletableFuture<Double>(),
CompletableFuture.completedFuture(42),
).anyOfCompletableFutureAny().await() shouldBe 42
listOf<CompletableFuture<*>>().anyOfCompletableFutureAny().isDone.shouldBeFalse()
).anyOfCompletableFuture().await() shouldBe 42
listOf<CompletableFuture<*>>().anyOfCompletableFuture().isDone.shouldBeFalse()

setOf(
CompletableFuture<String>(),
CompletableFuture<Double>(),
CompletableFuture.completedFuture(42),
).anyOfCompletableFutureAny().await() shouldBe 42
).anyOfCompletableFuture().await() shouldBe 42

arrayOf(
CompletableFuture<String>(),
CompletableFuture<Double>(),
CompletableFuture.completedFuture(42),
).anyOfCompletableFutureAny().await() shouldBe 42
arrayOf<CompletableFuture<*>>().anyOfCompletableFutureAny().isDone.shouldBeFalse()
).anyOfCompletableFuture().await() shouldBe 42
arrayOf<CompletableFuture<*>>().anyOfCompletableFuture().isDone.shouldBeFalse()

////////////////////////////////////////

Expand Down Expand Up @@ -187,24 +187,24 @@ class CompletableFutureExtensionsTest : FunSpec({
CompletableFuture<String>(),
CompletableFuture<Double>(),
CompletableFuture.completedFuture(42),
).anyOfSuccessCompletableFutureAny().await() shouldBe 42
).anyOfSuccessCompletableFuture().await() shouldBe 42
shouldThrow<NoCfsProvidedException> {
listOf<CompletableFuture<*>>().anyOfSuccessCompletableFutureAny().await()
listOf<CompletableFuture<*>>().anyOfSuccessCompletableFuture().await()
}

setOf(
CompletableFuture<String>(),
CompletableFuture<Double>(),
CompletableFuture.completedFuture(42),
).anyOfSuccessCompletableFutureAny().await() shouldBe 42
).anyOfSuccessCompletableFuture().await() shouldBe 42

arrayOf(
CompletableFuture<String>(),
CompletableFuture<Double>(),
CompletableFuture.completedFuture(42),
).anyOfSuccessCompletableFutureAny().await() shouldBe 42
).anyOfSuccessCompletableFuture().await() shouldBe 42
shouldThrow<NoCfsProvidedException> {
arrayOf<CompletableFuture<*>>().anyOfSuccessCompletableFutureAny().await()
arrayOf<CompletableFuture<*>>().anyOfSuccessCompletableFuture().await()
}

}
Expand Down

0 comments on commit d10d570

Please sign in to comment.