-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtask.go
More file actions
36 lines (30 loc) · 704 Bytes
/
Copy pathtask.go
File metadata and controls
36 lines (30 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package nasync
import (
"reflect"
)
// model function into task
type task struct {
handler reflect.Value
params []reflect.Value
}
func newTask(handler interface{}, params ...interface{}) *task {
handlerValue := reflect.ValueOf(handler)
if handlerValue.Kind() == reflect.Func {
task := task{
handler: handlerValue,
params: make([]reflect.Value, 0),
}
if paramNum := len(params); paramNum > 0 {
task.params = make([]reflect.Value, paramNum)
for index, v := range params {
task.params[index] = reflect.ValueOf(v)
}
}
return &task
}
panic("handler not func")
}
//Do single task functions do
func (t *task) Do() []reflect.Value {
return t.handler.Call(t.params)
}