Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
createServicePolicy: Convert callbacks to methods (#5188)
Both RetryPolicy and CircuitBreakerPolicy from the Cockatiel library allow for listening for events using `on*` methods. For instance, if you have a retry policy, you can listen for when the function is retried like so: ``` typescript retryPolicy.onRetry(() => { // ... }) ``` Our "service policy" allows for listening to some of the same events as well as the "degraded" event. Instead of exposing `on*` methods, however, `createServicePolicy` takes callbacks in an options bag: ``` typescript createServicePolicy({ // ... onRetry: () => { // ... } ) ``` For parity with Cockatiel — and for easier use in general — this commit changes the API so that the object that `createServicePolicy` returns now includes similar `on*` methods. This way you can say: ``` typescript const policy = createServicePolicy({ ... }); policy.onRetry(() => { // ... }); ```
- Loading branch information