forked from eosspark/geos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_context.go
74 lines (66 loc) · 1.36 KB
/
io_context.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package asio
type IoContext struct {
service ReactorService
}
func NewIoContext() *IoContext {
return &IoContext{}
}
func (i *IoContext) Run() {
i.GetService().run()
}
func (i *IoContext) Stop() {
i.GetService().stop()
}
func (i *IoContext) Post(op func(err error)) {
//post function in a separate goroutine
go i.GetService().post(postOp{op, nil})
}
//type operation struct {
// function interface{}
// argument []interface{}
//}
type ReactorService interface {
run()
stop()
post(op operation)
notify(op operation)
}
//func doReactor(opr operation) {
// opv := reflect.ValueOf(opr.function)
// opt := reflect.TypeOf(opr.function)
//
// if opt == nil {
// println("invalid operation <nil>")
// }
//
// if opt.Kind() != reflect.Func {
// println("op must be a callback function")
// return
// }
//
// opNum := opt.NumIn()
// if opNum != len(opr.argument) {
// println("invalid arguments", "arguments needs:", opNum)
// return
// }
//
// opArgs := make([]reflect.Value, opNum)
//
// for i:=0; i<opt.NumIn(); i++ {
// if opr.argument[i] == nil {
// opArgs[i] = reflect.Zero(opt.In(i))
// continue
// }
//
// if !reflect.TypeOf(opr.argument[i]).AssignableTo(opt.In(i)) {
// println("invalid arguments", "wrong args#", i)
// return
// }
//
// opArgs[i] = reflect.ValueOf(opr.argument[i])
// }
//
// //fmt.Println("args", opArgs)
//
// opv.Call(opArgs)
//}