@benjstephenson/circuit-breaker-ts
v0.0.3
Published
Small circuit breaker implementation to wrap a lazy thunk
Downloads
4
Readme
circuit-breaker-ts
Dependency free circuit breaker.
Given a thunk () => Promise<A>
, allow a configurable number of errors to occur before any subsequent calls to the thunk are short-circuited for a set amount of time.
The error threshold, error message and back off time are configurable.
Useful for protecting calls to external services that may experience an outage.
A convenience function that returns a singleton is available so that an instance can be built at app startup and injected into services.
Inspired by a great blog post on circuit breakers in the functional world