diff --git a/examples/decorator_test.go b/examples/decorator_test.go index e1537a7..6caceba 100644 --- a/examples/decorator_test.go +++ b/examples/decorator_test.go @@ -100,18 +100,22 @@ func TestCacheFuncWithMoreParams(t *testing.T) { } // Cacheable Function - fnCached := gofnext.CacheFn1(fnWrap) + fnCachedInner := gofnext.CacheFn1(fnWrap) + fnCached := func(name string, age, gender int) int { + return fnCachedInner(Stu{name, age, gender}) + } // Execute the function multi times in parallel. parallelCall(func() { - score := fnCached(Stu{"Alex", 20, 1}) + score := fnCached("Alex", 20, 1) if score != 10 { t.Errorf("score should be 10, but get %d", score) } - fnCached(Stu{"Jhon", 21, 0}) - fnCached(Stu{"Alex", 20, 1}) + fnCached("Jhon", 21, 0) + fnCached("Alex", 20, 1) }, 10) + // Test count if executeCount != 2 { t.Errorf("executeCount should be 2, but get %d", executeCount) } diff --git a/readme.md b/readme.md index ecb89f9..9c231e8 100644 --- a/readme.md +++ b/readme.md @@ -197,19 +197,23 @@ Refer to: [decorator example](https://github.com/ahuigo/gofnext/blob/main/exampl } // Cacheable Function - fnCached := gofnext.CacheFn1(fnWrap) + fnCachedInner := gofnext.CacheFn1(fnWrap) + fnCached := func(name string, age, gender int) int { + return fnCachedInner(Stu{name, age, gender}) + } // Execute the function multi times in parallel. parallelCall(func() { - score := fnCached(Stu{"Alex", 20, 1}) + score := fnCached("Alex", 20, 1) if score != 10 { t.Errorf("score should be 10, but get %d", score) } - fnCached(Stu{"Jhon", 21, 0}) - fnCached(Stu{"Alex", 20, 1}) + fnCached("Jhon", 21, 0) + fnCached("Alex", 20, 1) }, 10) - if executeCount != 2 { + // Test Count + if executeCount != 2 { t.Errorf("executeCount should be 2, but get %d", executeCount) } diff --git a/readme.zh.md b/readme.zh.md index b8ab31b..775e72a 100644 --- a/readme.zh.md +++ b/readme.zh.md @@ -197,19 +197,23 @@ func main() { } // Cacheable Function - fnCached := gofnext.CacheFn1(fnWrap) + fnCachedInner := gofnext.CacheFn1(fnWrap) + fnCached := func(name string, age, gender int) int { + return fnCachedInner(Stu{name, age, gender}) + } // Execute the function multi times in parallel. parallelCall(func() { - score := fnCached(Stu{"Alex", 20, 1}) + score := fnCached("Alex", 20, 1) if score != 10 { t.Errorf("score should be 10, but get %d", score) } - fnCached(Stu{"Jhon", 21, 0}) - fnCached(Stu{"Alex", 20, 1}) + fnCached("Jhon", 21, 0) + fnCached("Alex", 20, 1) }, 10) - if executeCount != 2 { + // Test Count + if executeCount != 2 { t.Errorf("executeCount should be 2, but get %d", executeCount) }