Skip to content

Commit

Permalink
Arrow Resilience (#2885)
Browse files Browse the repository at this point in the history
* Split CircuitBreaker and Schedule into its own package

Co-authored-by: Simon Vergauwen <[email protected]>
  • Loading branch information
serras and nomisRev authored Jan 19, 2023
1 parent 0dd37b5 commit ad8ea21
Show file tree
Hide file tree
Showing 32 changed files with 3,083 additions and 1 deletion.
3 changes: 3 additions & 0 deletions arrow-libs/core/arrow-core/karma.config.d/timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config.set({
browserDisconnectTimeout: 60000
});
3 changes: 3 additions & 0 deletions arrow-libs/fx/arrow-fx-coroutines/karma.config.d/timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config.set({
browserDisconnectTimeout: 60000
});
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import kotlin.time.DurationUnit
* ```
* <!--- KNIT example-circuitbreaker-02.kt -->
*/
@Deprecated(deprecatedInFavorOfArrowFxResilience, ReplaceWith("CircuitBreaker", "arrow.fx.resilience.CircuitBreaker"))
public class CircuitBreaker
private constructor(
private val state: AtomicRef<State>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package arrow.fx.coroutines

internal const val deprecatedInFavorOfArrowFxResilience =
"This is now part of the arrow-fx-resilience module, and will be removed from arrow-fx-coroutines in version 2.0. Please update your project dependencies."
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ import kotlin.time.DurationUnit.NANOSECONDS
* ```
* <!--- KNIT example-schedule-08.kt -->
*/
@Deprecated(deprecatedInFavorOfArrowFxResilience, ReplaceWith("Schedule", "arrow.fx.resilience.Schedule"))
public sealed class Schedule<Input, Output> {

public abstract suspend fun <C> repeatOrElseEither(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import kotlinx.coroutines.flow.DEFAULT_CONCURRENCY
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flattenMerge
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -56,6 +55,7 @@ import kotlin.time.ExperimentalTime
*
* @param schedule - the [Schedule] used for retrying the collection of the flow
*/
@Deprecated(deprecatedInFavorOfArrowFxResilience, ReplaceWith("retry", "arrow.fx.resilience.retry"))
public fun <A, B> Flow<A>.retry(schedule: Schedule<Throwable, B>): Flow<A> = flow {
(schedule as Schedule.ScheduleImpl<Any?, Throwable, B>)
var dec: Schedule.Decision<Any?, B>
Expand Down
6 changes: 6 additions & 0 deletions arrow-libs/fx/arrow-fx-resilience/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Module main
# Arrow Fx Resilience

[![Arrow Fx logo](https://raw.githubusercontent.com/arrow-kt/arrow-site/main/docs/img/fx/arrow-fx-brand-sidebar.svg?sanitize=true)](https://arrow-kt.io)

Λrrow Fx Resilience is part of Arrow Fx [**Λrrow**](https://arrow-kt.io/docs/fx/).
180 changes: 180 additions & 0 deletions arrow-libs/fx/arrow-fx-resilience/api/arrow-fx-resilience.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
public final class arrow/fx/resilience/CircuitBreaker {
public static final field Companion Larrow/fx/resilience/CircuitBreaker$Companion;
public synthetic fun <init> (Ljava/util/concurrent/atomic/AtomicReference;IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun awaitClose (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun doOnClosed (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/CircuitBreaker;
public final fun doOnHalfOpen (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/CircuitBreaker;
public final fun doOnOpen (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/CircuitBreaker;
public final fun doOnRejectedTask (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/CircuitBreaker;
public final fun protectEither (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun protectOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun state (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class arrow/fx/resilience/CircuitBreaker$Companion {
public final fun of (IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun of$default (Larrow/fx/resilience/CircuitBreaker$Companion;IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public final fun of-3c68mSE (IJDJLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun of-3c68mSE$default (Larrow/fx/resilience/CircuitBreaker$Companion;IJDJLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class arrow/fx/resilience/CircuitBreaker$ExecutionRejected : java/lang/Throwable {
public fun <init> (Ljava/lang/String;Larrow/fx/resilience/CircuitBreaker$State;)V
public final fun getReason ()Ljava/lang/String;
public final fun getState ()Larrow/fx/resilience/CircuitBreaker$State;
}

public abstract class arrow/fx/resilience/CircuitBreaker$State {
}

public final class arrow/fx/resilience/CircuitBreaker$State$Closed : arrow/fx/resilience/CircuitBreaker$State {
public fun <init> (I)V
public fun equals (Ljava/lang/Object;)Z
public final fun getFailures ()I
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/fx/resilience/CircuitBreaker$State$HalfOpen : arrow/fx/resilience/CircuitBreaker$State {
public fun <init> (D)V
public synthetic fun <init> (JLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getResetTimeout-UwyO8pc ()J
public final fun getResetTimeoutNanos ()D
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/fx/resilience/CircuitBreaker$State$Open : arrow/fx/resilience/CircuitBreaker$State {
public fun <init> (JD)V
public synthetic fun <init> (JJLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getExpiresAt ()J
public final fun getResetTimeout-UwyO8pc ()J
public final fun getResetTimeoutNanos ()D
public final fun getStartedAt ()J
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class arrow/fx/resilience/FlowKt {
public static final fun retry (Lkotlinx/coroutines/flow/Flow;Larrow/fx/resilience/Schedule;)Lkotlinx/coroutines/flow/Flow;
}

public abstract class arrow/fx/resilience/Schedule {
public static final field Companion Larrow/fx/resilience/Schedule$Companion;
public final fun and (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public abstract fun andThen (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public abstract fun check (Lkotlin/jvm/functions/Function3;)Larrow/fx/resilience/Schedule;
public abstract fun choose (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public final fun collect ()Larrow/fx/resilience/Schedule;
public final fun combine (Larrow/fx/resilience/Schedule;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public abstract fun combineNanos (Larrow/fx/resilience/Schedule;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun compose (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public final fun const (Ljava/lang/Object;)Larrow/fx/resilience/Schedule;
public abstract fun contramap (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun delay (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun delayedNanos (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun dimap (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule;
public final fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function3;)Larrow/fx/resilience/Schedule;
public abstract fun foldLazy (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Larrow/fx/resilience/Schedule;
public abstract fun forever ()Larrow/fx/resilience/Schedule;
public final fun jittered (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule;
public final fun jittered (Lkotlin/random/Random;)Larrow/fx/resilience/Schedule;
public static synthetic fun jittered$default (Larrow/fx/resilience/Schedule;Lkotlin/random/Random;ILjava/lang/Object;)Larrow/fx/resilience/Schedule;
public final fun jitteredDuration (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule;
public abstract fun logInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public abstract fun logOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public abstract fun map (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule;
public final fun modify (Lkotlin/jvm/functions/Function3;)Larrow/fx/resilience/Schedule;
public abstract fun modifyNanos (Lkotlin/jvm/functions/Function3;)Larrow/fx/resilience/Schedule;
public abstract fun not ()Larrow/fx/resilience/Schedule;
public final fun or (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public abstract fun pipe (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public final fun repeat (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun repeatAsFlow (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun repeatOrElse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun repeatOrElseAsFlow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun repeatOrElseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun repeatOrElseEitherAsFlow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun untilInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun untilOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun void ()Larrow/fx/resilience/Schedule;
public final fun whileInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun whileOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun zip (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public abstract fun zip (Larrow/fx/resilience/Schedule;Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun zipLeft (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public final fun zipRight (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
}

public final class arrow/fx/resilience/Schedule$Companion {
public final fun collect ()Larrow/fx/resilience/Schedule;
public final fun decision ()Larrow/fx/resilience/Schedule;
public final fun delayInNanos ()Larrow/fx/resilience/Schedule;
public final fun delayedDuration (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public final fun delayedNanos (Larrow/fx/resilience/Schedule;)Larrow/fx/resilience/Schedule;
public final fun doUntil (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun doWhile (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun duration ()Larrow/fx/resilience/Schedule;
public final fun exponential (DD)Larrow/fx/resilience/Schedule;
public static synthetic fun exponential$default (Larrow/fx/resilience/Schedule$Companion;DDILjava/lang/Object;)Larrow/fx/resilience/Schedule;
public final fun exponential-VtjQ1oo (JD)Larrow/fx/resilience/Schedule;
public static synthetic fun exponential-VtjQ1oo$default (Larrow/fx/resilience/Schedule$Companion;JDILjava/lang/Object;)Larrow/fx/resilience/Schedule;
public final fun fibonacci (D)Larrow/fx/resilience/Schedule;
public final fun fibonacci-LRDsOJo (J)Larrow/fx/resilience/Schedule;
public final fun forever ()Larrow/fx/resilience/Schedule;
public final fun identity ()Larrow/fx/resilience/Schedule;
public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Larrow/fx/resilience/Schedule;
public final fun linear (D)Larrow/fx/resilience/Schedule;
public final fun linear-LRDsOJo (J)Larrow/fx/resilience/Schedule;
public final fun logInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun logOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun never ()Larrow/fx/resilience/Schedule;
public final fun once ()Larrow/fx/resilience/Schedule;
public final fun recurs (I)Larrow/fx/resilience/Schedule;
public final fun spaced (D)Larrow/fx/resilience/Schedule;
public final fun spaced-LRDsOJo (J)Larrow/fx/resilience/Schedule;
public final fun unfold (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule;
public final fun unfoldLazy (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule;
public final fun unit ()Larrow/fx/resilience/Schedule;
}

public final class arrow/fx/resilience/Schedule$Decision {
public static final field Companion Larrow/fx/resilience/Schedule$Decision$Companion;
public fun <init> (ZDLjava/lang/Object;Larrow/core/Eval;)V
public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule$Decision;
public final fun combine (Larrow/fx/resilience/Schedule$Decision;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule$Decision;
public final fun combineNanos (Larrow/fx/resilience/Schedule$Decision;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/resilience/Schedule$Decision;
public final fun component1 ()Z
public final fun component2 ()D
public final fun component3 ()Ljava/lang/Object;
public final fun component4 ()Larrow/core/Eval;
public final fun copy (ZDLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/resilience/Schedule$Decision;
public static synthetic fun copy$default (Larrow/fx/resilience/Schedule$Decision;ZDLjava/lang/Object;Larrow/core/Eval;ILjava/lang/Object;)Larrow/fx/resilience/Schedule$Decision;
public fun equals (Ljava/lang/Object;)Z
public final fun getCont ()Z
public final fun getDelayInNanos ()D
public final fun getDuration-UwyO8pc ()J
public final fun getFinish ()Larrow/core/Eval;
public final fun getState ()Ljava/lang/Object;
public fun hashCode ()I
public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule$Decision;
public final fun mapLeft (Lkotlin/jvm/functions/Function1;)Larrow/fx/resilience/Schedule$Decision;
public final fun not ()Larrow/fx/resilience/Schedule$Decision;
public fun toString ()Ljava/lang/String;
}

public final class arrow/fx/resilience/Schedule$Decision$Companion {
public final fun cont (DLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/resilience/Schedule$Decision;
public final fun cont-KLykuaI (JLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/resilience/Schedule$Decision;
public final fun done (DLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/resilience/Schedule$Decision;
public final fun done-KLykuaI (JLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/resilience/Schedule$Decision;
}

public final class arrow/fx/resilience/ScheduleKt {
public static final fun retry (Larrow/fx/resilience/Schedule;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun retryOrElse (Larrow/fx/resilience/Schedule;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun retryOrElseEither (Larrow/fx/resilience/Schedule;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

46 changes: 46 additions & 0 deletions arrow-libs/fx/arrow-fx-resilience/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)
alias(libs.plugins.arrowGradleConfig.publish)
}

apply(plugin = "io.kotest.multiplatform")
apply(from = property("TEST_COVERAGE"))

val enableCompatibilityMetadataVariant =
providers.gradleProperty("kotlin.mpp.enableCompatibilityMetadataVariant")
.forUseAtConfigurationTime().orNull?.toBoolean() == true

if (enableCompatibilityMetadataVariant) {
tasks.withType<Test>().configureEach {
exclude("**/*")
}
}

kotlin {
sourceSets {
commonMain {
dependencies {
api(projects.arrowCore)
implementation(projects.arrowFxCoroutines)
compileOnly(libs.kotlin.stdlibCommon)
implementation(libs.coroutines.core)
}
}
if (!enableCompatibilityMetadataVariant) {
commonTest {
dependencies {
implementation(libs.coroutines.test)
implementation(libs.kotest.frameworkEngine)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
}
}
jvmTest {
dependencies {
runtimeOnly(libs.kotest.runnerJUnit5)
}
}
}
}
}
2 changes: 2 additions & 0 deletions arrow-libs/fx/arrow-fx-resilience/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Maven publishing configuration
pom.name=Arrow-Fx-Resilience
3 changes: 3 additions & 0 deletions arrow-libs/fx/arrow-fx-resilience/karma.config.d/timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config.set({
browserDisconnectTimeout: 60000
});
5 changes: 5 additions & 0 deletions arrow-libs/fx/arrow-fx-resilience/knit.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
knit.package=arrow.fx.resilience.examples
knit.dir=src/jvmTest/kotlin/examples/

test.package=arrow.fx.resilience.examples.test
test.dir=src/jvmTest/kotlin/examples/autogenerated/
Loading

0 comments on commit ad8ea21

Please sign in to comment.