/
rpcli_procedure.go
69 lines (57 loc) · 1.46 KB
/
rpcli_procedure.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
package rpcli
import (
"git.golaxy.org/core/runtime"
"git.golaxy.org/core/util/uid"
"reflect"
)
var (
Main = uid.Nil // 主过程
)
// IProcedure 过程接口
type IProcedure interface {
_IProcedure
// GetCli 获取RPC客户端
GetCli() *RPCli
// GetId 获取实体Id
GetId() uid.Id
// GetReflected 获取反射值
GetReflected() reflect.Value
// RPC RPC调用
RPC(service, comp, method string, args ...any) runtime.AsyncRet
// OneWayRPC 单向RPC调用
OneWayRPC(service, comp, method string, args ...any) error
}
type _IProcedure interface {
setup(cli *RPCli, entityId uid.Id, composite any)
}
// Procedure 过程
type Procedure struct {
cli *RPCli
id uid.Id
reflected reflect.Value
}
func (p *Procedure) setup(cli *RPCli, entityId uid.Id, composite any) {
p.cli = cli
p.id = entityId
p.reflected = reflect.ValueOf(composite)
}
// GetCli 获取RPC客户端
func (p *Procedure) GetCli() *RPCli {
return p.cli
}
// GetId 获取实体Id
func (p *Procedure) GetId() uid.Id {
return p.id
}
// GetReflected 获取反射值
func (p *Procedure) GetReflected() reflect.Value {
return p.reflected
}
// RPC RPC调用
func (p *Procedure) RPC(service, comp, method string, args ...any) runtime.AsyncRet {
return p.cli.RPCToEntity(p.id, service, comp, method, args...)
}
// OneWayRPC 单向RPC调用
func (p *Procedure) OneWayRPC(service, comp, method string, args ...any) error {
return p.cli.OneWayRPCToEntity(p.id, service, comp, method, args...)
}