Skip to content

Commit

Permalink
Change ADR after internal discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed May 17, 2024
1 parent e2be112 commit dd01764
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions apps/website/docs/adr/barrier_circuit_breaker.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,35 @@ 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).
Added new _Events_ to [_Barrier_](/api/primitives/barrier) that allow to implement a circuit breaker pattern.

```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,
});
},
});

const $times = createStore(0);

sample({
clock: authBarrier.performed, // <- New Event on Barrier
filter: authBarrier.$active,
source: $times,
fn: (times) => times + 1,
target: $times,
});

sample({
clock: $times,
filter: (times) => times > 10,
target: authBarrier.forceDeactivate, // <- New Event on Barrier
});

sample({
clock: authBarrier.deactivated,
target: $times.reinit,
});
```

Expand Down

0 comments on commit dd01764

Please sign in to comment.