-
Notifications
You must be signed in to change notification settings - Fork 4
/
callable.go
44 lines (36 loc) · 1017 Bytes
/
callable.go
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
37
38
39
40
41
42
43
44
package eva
// Callable is interface, that Call function for task in goroutines pool.
type Callable interface {
// Call perform function.
Call()
// Error returns function Call error.
Error() error
// Result returns function Call result.
Result() interface{}
}
// CustomCallable (implement Callable interface) for task in goroutines pool.
type CustomCallable struct {
f func(...interface{}) (interface{}, error)
args []interface{}
result interface{}
error error
}
// NewCustomCallable is constructor for CustomCallable
func NewCustomCallable(f func(...interface{}) (interface{}, error), args ...interface{}) *CustomCallable {
return &CustomCallable{
f: f,
args: args,
}
}
// Call perform function.
func (cc *CustomCallable) Call() {
cc.result, cc.error = cc.f(cc.args...)
}
// Error returns function Call error.
func (cc *CustomCallable) Error() error {
return cc.error
}
// Result returns function Call result.
func (cc *CustomCallable) Result() interface{} {
return cc.result
}