-
Notifications
You must be signed in to change notification settings - Fork 172
Open
Description
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.
jarreds and mseld
Metadata
Metadata
Assignees
Labels
No labels