Skip to content

Commit

Permalink
Fix problem with KMP 1.9.20
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Nov 2, 2023
1 parent 85f703c commit a5720be
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,26 +621,31 @@ private constructor(
onClosed: suspend () -> Unit = { },
onHalfOpen: suspend () -> Unit = { },
onOpen: suspend () -> Unit = { },
): CircuitBreaker =
CircuitBreaker(
): CircuitBreaker {
require(maxFailures >= 0) {
"maxFailures expected to be greater than or equal to 0, but was $maxFailures"
}
require(resetTimeoutNanos > 0) {
"resetTimeout expected to be greater than 0, but was $resetTimeoutNanos"
}
require(exponentialBackoffFactor > 0) {
"exponentialBackoffFactor expected to be greater than 0, but was $exponentialBackoffFactor"
}
require(maxResetTimeoutNanos > 0) {
"maxResetTimeout expected to be greater than 0, but was $maxResetTimeoutNanos"
}
return CircuitBreaker(
state = AtomicRef(Closed(0)),
maxFailures = maxFailures
.takeIf { it >= 0 }
.let { requireNotNull(it) { "maxFailures expected to be greater than or equal to 0, but was $maxFailures" } },
resetTimeoutNanos = resetTimeoutNanos
.takeIf { it > 0 }
.let { requireNotNull(it) { "resetTimeout expected to be greater than 0, but was $resetTimeoutNanos" } },
exponentialBackoffFactor = exponentialBackoffFactor
.takeIf { it > 0 }
.let { requireNotNull(it) { "exponentialBackoffFactor expected to be greater than 0, but was $exponentialBackoffFactor" } },
maxResetTimeoutNanos = maxResetTimeoutNanos
.takeIf { it > 0 }
.let { requireNotNull(it) { "maxResetTimeout expected to be greater than 0, but was $maxResetTimeoutNanos" } },
maxFailures = maxFailures,
resetTimeoutNanos = resetTimeoutNanos,
exponentialBackoffFactor = exponentialBackoffFactor,
maxResetTimeoutNanos = maxResetTimeoutNanos,
onRejected = onRejected,
onClosed = onClosed,
onHalfOpen = onHalfOpen,
onOpen = onOpen
)
}

/**
* Attempts to create a [CircuitBreaker].
Expand Down Expand Up @@ -682,20 +687,10 @@ private constructor(
onOpen: suspend () -> Unit = suspend { },
): CircuitBreaker =
of(
maxFailures = maxFailures
.takeIf { it >= 0 }
.let { requireNotNull(it) { "maxFailures expected to be greater than or equal to 0, but was $maxFailures" } },
resetTimeoutNanos = resetTimeout
.takeIf { it.isPositive() && it != Duration.ZERO }
.let { requireNotNull(it) { "resetTimeout expected to be greater than ${Duration.ZERO}, but was $resetTimeout" } }
.toDouble(DurationUnit.NANOSECONDS),
exponentialBackoffFactor = exponentialBackoffFactor
.takeIf { it > 0 }
.let { requireNotNull(it) { "exponentialBackoffFactor expected to be greater than 0, but was $exponentialBackoffFactor" } },
maxResetTimeoutNanos = maxResetTimeout
.takeIf { it.isPositive() && it != Duration.ZERO }
.let { requireNotNull(it) { "maxResetTimeout expected to be greater than ${Duration.ZERO}, but was $maxResetTimeout" } }
.toDouble(DurationUnit.NANOSECONDS),
maxFailures = maxFailures,
resetTimeoutNanos = resetTimeout.toDouble(DurationUnit.NANOSECONDS),
exponentialBackoffFactor = exponentialBackoffFactor,
maxResetTimeoutNanos = maxResetTimeout.toDouble(DurationUnit.NANOSECONDS),
onRejected = onRejected,
onClosed = onClosed,
onHalfOpen = onHalfOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,24 +520,28 @@ private constructor(
onClosed: suspend () -> Unit = suspend { },
onHalfOpen: suspend () -> Unit = suspend { },
onOpen: suspend () -> Unit = suspend { }
): CircuitBreaker =
CircuitBreaker(
): CircuitBreaker {
require(resetTimeout > Duration.ZERO) {
"resetTimeout expected to be greater than ${Duration.ZERO}, but was $resetTimeout"
}
require(exponentialBackoffFactor > 0) {
"exponentialBackoffFactor expected to be greater than 0, but was $exponentialBackoffFactor"
}
require(maxResetTimeout > Duration.ZERO) {
"maxResetTimeout expected to be greater than ${Duration.ZERO}, but was $maxResetTimeout"
}
return CircuitBreaker(
state = AtomicRef(Closed(openingStrategy)),
resetTimeout = resetTimeout
.takeIf { it.isPositive() && it != Duration.ZERO }
.let { requireNotNull(it) { "resetTimeout expected to be greater than ${Duration.ZERO}, but was $resetTimeout" } },
exponentialBackoffFactor = exponentialBackoffFactor
.takeIf { it > 0 }
.let { requireNotNull(it) { "exponentialBackoffFactor expected to be greater than 0, but was $exponentialBackoffFactor" } },
maxResetTimeout = maxResetTimeout
.takeIf { it.isPositive() && it != Duration.ZERO }
.let { requireNotNull(it) { "maxResetTimeout expected to be greater than ${Duration.ZERO}, but was $maxResetTimeout" } },
resetTimeout = resetTimeout,
exponentialBackoffFactor = exponentialBackoffFactor,
maxResetTimeout = maxResetTimeout,
timeSource = timeSource,
onRejected = onRejected,
onClosed = onClosed,
onHalfOpen = onHalfOpen,
onOpen = onOpen
)
}
}

public sealed class OpeningStrategy {
Expand Down

0 comments on commit a5720be

Please sign in to comment.