-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5acdb7
commit e2be112
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: Barrier Circuit Breaker | ||
|
||
outline: [2, 3] | ||
|
||
version: v0.13 | ||
--- | ||
|
||
# Barrier Circuit Breaker | ||
|
||
This ADR is effective starting from [v0.13](/releases/0-13). | ||
|
||
::: tip TL;DR | ||
|
||
Added optional `circuitBreaker` to [`createBarrier`](/api/factories/create_barrier) to allow adding custom circuit breaker logic to a [_Barrier_](/api/primitives/barrier). | ||
|
||
```ts | ||
const authBarrier = createBarrier({ | ||
activateOn: { | ||
failure: isHttpErrorCode(401), | ||
}, | ||
perform: [getTokenMutation], | ||
circuitBreaker({ performed, deactivated, $active, breakCircuit }) { | ||
const $times = createStore(0); | ||
|
||
sample({ | ||
clock: performed, | ||
filter: $active, | ||
source: $times, | ||
fn: (times) => times + 1, | ||
target: $times, | ||
}); | ||
|
||
sample({ | ||
clock: $times, | ||
filter: (times) => times > 10, | ||
target: breakCircuit, | ||
}); | ||
|
||
sample({ | ||
clock: deactivated, | ||
target: $times.reinit, | ||
}); | ||
}, | ||
}); | ||
``` | ||
|
||
::: | ||
|
||
## Problem | ||
|
||
::: tip | ||
Original issue: [farfetched#458](https://github.com/igorkamyshev/farfetched/issues/458) | ||
::: |