connor4312 / cockatiel

🐦 A resilience and fault-handling library. Supports Backoffs, Retries, Circuit Breakers, Timeouts, Bulkhead Isolation, and Fallbacks.
MIT License
1.59k stars 50 forks source link

circuitBreaker .d.ts example doesn't provide a halfOpenAfter and would result in a TS error #24

Closed Tyriar closed 4 years ago

Tyriar commented 4 years ago

From .d.ts:

     * // Break if more than 20% of requests fail in a 30 second time window:
     * const breaker = Policy
     *  .handleAll()
     *  .circuitBreaker(new SamplingBreaker(0.2, 30 * 1000));
     *
     * export function handleRequest() {
     *   return breaker.execute(() => getInfoFromDatabase());
     * }
     * ```
     *
     * @param breaker -- The circuit breaker to use. This package exports
     * ConsecutiveBreaker and SamplingBreakers for you to use.
     * @param halfOpenAfter -- Time after failures to try to open the circuit
     * breaker again. Defaults to 10 seconds.
     */
    circuitBreaker(halfOpenAfter: number, breaker: IBreaker): CircuitBreakerPolicy;

image

Tyriar commented 4 years ago

"Defaults to 10 seconds." is still there, does that mean is 0 is passed in for halfOpenAfter?

connor4312 commented 4 years ago

There is no default, halfOpenAfter must be manually specified. Fixed that in the docs. I realized as a library I didn't know enough about the underlying service to determine an appropriate interval.

Updated docs:

https://github.com/connor4312/cockatiel/blob/d7b1d4f9a04f9f6eb0bbe76403004ce7a424b7fe/src/Policy.ts#L392-L423