From d95a7c610116d03b1f63b5c89517db3123cea414 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sun, 8 Jan 2023 21:09:41 +0800 Subject: [PATCH] fix: fix example function bug in function package --- function/function.go | 8 -------- function/function_example_test.go | 12 ++++++------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/function/function.go b/function/function.go index e453572..e8bf2a8 100644 --- a/function/function.go +++ b/function/function.go @@ -145,14 +145,6 @@ func unsafeInvokeFunc(fn any, args ...any) []reflect.Value { return fv.Call(params) } -func functionValue(function any) reflect.Value { - v := reflect.ValueOf(function) - if v.Kind() != reflect.Func { - panic(fmt.Sprintf("Invalid function type, value of type %T", function)) - } - return v -} - func mustBeFunction(function any) { v := reflect.ValueOf(function) if v.Kind() != reflect.Func { diff --git a/function/function_example_test.go b/function/function_example_test.go index 823d5fd..5c6894d 100644 --- a/function/function_example_test.go +++ b/function/function_example_test.go @@ -108,21 +108,21 @@ func ExampleDebounced() { } func ExampleSchedule() { - var result []string + count := 0 - appendFn := func(s string) { - result = append(result, s) + increase := func() { + count++ } - stop := Schedule(1*time.Second, appendFn, "*") + stop := Schedule(1*time.Second, increase) time.Sleep(3 * time.Second) close(stop) - fmt.Println(result) + fmt.Println(count) // Output: - // [* * *] + // 3 } func ExamplePipeline() {