I've tried to create a function in Go that used to retry any fail query functions (usually because serialization issue).
func retryer(functionA func(interface{}) (interface{}, []error), maxRetry int, waitBetween time.Duration) interface{} { //when no error in functionA, retryer returns whatever functionA returns //when maxRetry is reached, returns nil } The functions I want to retry are looked like this
func GetTopStudent(classId string) ([]Student, []error) { //queries top 10 students for class with classId } func GetAverageStudentScores(classId string, from time.Time, until time.Time) ([]Pair, []error) { //queries all average score using aggregate, grouping by studentId //Pair behaves like C++ pair<string,string> } But, the results is a compile error
cannot use GetTopStudent (type func(string) ([]Student, []error)) as type func(interface{}) (interface {}, []error) in argument to retryer I've tried to modify it a little and I got another compile error
cannot use GetTopStudent (type func(string) ([]Student, []error)) as type func(string) (interface {}, []error) in argument to retryer Can anyone help me creating a general function to wrap a function to retry on error?
interface{}'s, and cast them to the appropriate types inside those functions.