Skip to content

Commit

Permalink
Finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed May 29, 2024
1 parent fbf4e7f commit cab75f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
21 changes: 8 additions & 13 deletions apps/website/docs/recipes/barrier_circuit_breaker.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,17 @@ In this case, we can write some kind of circuit breaker that will stop the token

```ts
function barrierCircuitBreaker(barrier, { maxAttempts }) {
const $currentAttempt = createStore(0);
const $currentAttempt = createStore(0).on(
// every time after the Barrier is performed
barrier.forceDeactivate,
// increment the current attempt
(attempt) => attempt + 1
);

// Increment the current attempt
// every time after the Barrier is performed
sample({
clock: barrier.performed,
source: $burrentAttempt,
fn: (attempt) => attempt + 1,
target: $currentAttempt,
});

// force the Barrier to deactivate
sample({
clock: $currentAttemp,
// If the number of attempts exceeds the limit,
filter: (currentAttemp) => currentAttemp >= maxAttempts,
clock: $currentAttempt,
filter: (currentAttempt) => currentAttempt >= maxAttempts,
target: [
// force the Barrier to deactivate
barrier.forceDeactivate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ describe('Barrier API', () => {
barrier: Barrier,
{ maxAttempts }: { maxAttempts: number }
) {
const $currentAttempt = createStore(0);

sample({
clock: barrier.performed,
source: $currentAttempt,
fn: (attempt) => attempt + 1,
target: $currentAttempt,
});
const $currentAttempt = createStore(0).on(
barrier.forceDeactivate,
(attempt) => attempt + 1
);

sample({
clock: $currentAttempt,
Expand Down

0 comments on commit cab75f2

Please sign in to comment.