mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
fix: fix example function bug in function package
This commit is contained in:
@@ -145,14 +145,6 @@ func unsafeInvokeFunc(fn any, args ...any) []reflect.Value {
|
|||||||
return fv.Call(params)
|
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) {
|
func mustBeFunction(function any) {
|
||||||
v := reflect.ValueOf(function)
|
v := reflect.ValueOf(function)
|
||||||
if v.Kind() != reflect.Func {
|
if v.Kind() != reflect.Func {
|
||||||
|
|||||||
@@ -108,21 +108,21 @@ func ExampleDebounced() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleSchedule() {
|
func ExampleSchedule() {
|
||||||
var result []string
|
count := 0
|
||||||
|
|
||||||
appendFn := func(s string) {
|
increase := func() {
|
||||||
result = append(result, s)
|
count++
|
||||||
}
|
}
|
||||||
|
|
||||||
stop := Schedule(1*time.Second, appendFn, "*")
|
stop := Schedule(1*time.Second, increase)
|
||||||
|
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
close(stop)
|
close(stop)
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(count)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// [* * *]
|
// 3
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExamplePipeline() {
|
func ExamplePipeline() {
|
||||||
|
|||||||
Reference in New Issue
Block a user