def State.done

bend-kit-retry@0.3.0.0 · retry.bend:125

import bend-kit-retry@0.3.0.0/retry.bend as Retry
import Base

125# A closed success clears the failures. A closed failure opens the circuit when the window then holds threshold
126# failures. A half-open success closes it; a half-open failure opens it again for cooldown. An attempt that ends
127# while open changes nothing.
128def State.done(+c: Circuit, s: State, +now: Nat, failed: Bool) -> State:
129  match s:
130    case CircuitClosed{fs}:
131      match failed:
132        case False{}:
133          CircuitClosed{Nil{}}
134        case True{}:
135          closed.fail(c, fs, now)
136    case CircuitOpen{u}:
137      CircuitOpen{u}
138    case CircuitHalf{k}:
139      match failed:
140        case False{}:
141          CircuitClosed{Nil{}}
142        case True{}:
143          CircuitOpen{Nat.add(now, Circuit.cooldown(c))}

Uses (8)

Used by (1)