@@ -32,14 +32,18 @@ func UntilWithContext(ctx context.Context, testFn, fn AsyncFn) ([]any, error) {
3232
3333// until repeatedly calls the function until the test function returns true.
3434func until (parent context.Context , testFn , fn AsyncFn ) ([]any , error ) {
35- validateUntilFuncs (testFn , fn )
35+ isNoParam := validateUntilFuncs (testFn , fn )
3636
3737 ctx := getContext (parent )
3838
3939 for {
4040 out , _ := invokeAsyncFn (fn , ctx , nil )
4141
42- testOut , testErr := invokeAsyncFn (testFn , ctx , out )
42+ params := out
43+ if isNoParam {
44+ params = nil
45+ }
46+ testOut , testErr := invokeAsyncFn (testFn , ctx , params )
4347 if testErr != nil {
4448 return out , testErr
4549 }
@@ -52,7 +56,7 @@ func until(parent context.Context, testFn, fn AsyncFn) ([]any, error) {
5256}
5357
5458// validateUntilFuncs validates the test function and the execution function.
55- func validateUntilFuncs (testFn , fn AsyncFn ) {
59+ func validateUntilFuncs (testFn , fn AsyncFn ) ( isNoParam bool ) {
5660 if testFn == nil || fn == nil {
5761 panic (ErrNotFunction )
5862 }
@@ -74,9 +78,12 @@ func validateUntilFuncs(testFn, fn AsyncFn) {
7478 numIn --
7579 ii ++
7680 }
77- if numIn != ft .NumOut () {
81+ if numIn != 0 && numIn != ft .NumOut () {
7882 panic (ErrInvalidTestFunc )
7983 }
84+ if numIn == 0 {
85+ return true
86+ }
8087
8188 for oi < numIn {
8289 it := tft .In (ii ) // type of the value in the test function input parameters list
@@ -89,4 +96,6 @@ func validateUntilFuncs(testFn, fn AsyncFn) {
8996 ii ++
9097 oi ++
9198 }
99+
100+ return false
92101}
0 commit comments