Skip to content

createServicePolicy: Convert callbacks to methods#5188

Merged
mcmire merged 1 commit intomainfrom
convert-callbacks-to-methods
Jan 23, 2025
Merged

createServicePolicy: Convert callbacks to methods#5188
mcmire merged 1 commit intomainfrom
convert-callbacks-to-methods

Conversation

@mcmire
Copy link
Copy Markdown
Contributor

@mcmire mcmire commented Jan 23, 2025

Explanation

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:

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:

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:

const policy = createServicePolicy({ ... });
policy.onRetry(() => {
  // ...
});

References

Progresses #4994.
Pre-requisite to #4990.

Changelog

(Updated in PR.)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mcmire mcmire force-pushed the convert-callbacks-to-methods branch from f743806 to c576f76 Compare January 23, 2025 00:11
Both RetryPolicy and CircuitBreakerPolicy from the Cockatiel library
allow for listening for events using `on*` methods. Our "service policy"
allows for listening to some of the same events as well as the
"degraded" event. For parity with Cockatiel — and for easier use in
general — this commit removes the callbacks that `createServicePolicy`
takes and replaces them with `on*` methods.
@mcmire mcmire force-pushed the convert-callbacks-to-methods branch from c576f76 to a811bf6 Compare January 23, 2025 00:22
@mcmire mcmire marked this pull request as ready for review January 23, 2025 00:29
@mcmire mcmire requested a review from a team as a code owner January 23, 2025 00:29
@mcmire mcmire added the team-wallet-framework Deprecated: Please use `team-core-platform` instead. label Jan 23, 2025
Copy link
Copy Markdown
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvements

@mcmire mcmire merged commit dcc0df0 into main Jan 23, 2025
@mcmire mcmire deleted the convert-callbacks-to-methods branch January 23, 2025 23:00
zone-live pushed a commit that referenced this pull request Jan 27, 2025
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(() => {
  // ...
});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-wallet-framework Deprecated: Please use `team-core-platform` instead.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants