Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RetryIfValue option to retry on given values #107

Open
totemcaf opened this issue Dec 11, 2023 · 0 comments
Open

Add RetryIfValue option to retry on given values #107

totemcaf opened this issue Dec 11, 2023 · 0 comments

Comments

@totemcaf
Copy link

totemcaf commented Dec 11, 2023

Sometimes want to retry if the computed values does not satisfy certain conditions. For example, you are waiting for some change to be applied to a persisted entity, so you want to retry until the entity read from persistence satisfy certain condition.

Example:

func (h *Handler) waitForApproval(ctx context.Context, id ids.Id) (*Entity, error) {
	return retry.DoWithData(func() (*Entity, error) {
		return h.reader.FindById(ctx, id)
        }, retry.RetryIfData(func (e *Entity) bool {
		return e.Status != StatusApproved // retry if the Status is not approved
       })
}

New type and func:

type RetryIfDataFunc[T any] func(T) bool

func RetryIfData[T any](f RetryIfDataFunc[T]) Option { // Option[T] ??
    // ...
}

It is challenging to handle type for Options to ensure consistency.

If you consider this to be useful (for me it is), I can provide a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant