rpc.call helper 함수 추가

This commit is contained in:
2023-07-10 10:29:16 +09:00
parent 550374ef6f
commit e912c88993
2 changed files with 17 additions and 4 deletions

View File

@ -134,16 +134,14 @@ func (re *rpcEngine) loop(ctx context.Context, redisClient *redis.Client, chanNa
var errNoReceiver = errors.New("no receiver")
type RpcCallContext struct {
type callContext struct {
r Receiver
t primitive.ObjectID
}
var ErrCanExecuteHere = errors.New("go ahead")
func MakeCallContext(r Receiver) RpcCallContext { return RpcCallContext{r: r} }
func (c *RpcCallContext) Target(t primitive.ObjectID) { c.t = t }
func (c *RpcCallContext) Call(args ...any) error {
func (c callContext) call(args ...any) error {
if c.r.TargetExists(c.t) {
// 여기 있네?
return ErrCanExecuteHere
@ -168,6 +166,14 @@ func (c *RpcCallContext) Call(args ...any) error {
return engine.publish(serialized)
}
func CallOrGo(r Receiver, target primitive.ObjectID, args ...any) error {
cc := callContext{
r: r,
t: target,
}
return cc.call(args...)
}
func encode(target primitive.ObjectID, receiver string, funcname string, args ...any) ([]byte, error) {
buff := new(bytes.Buffer)

7
rpc/rpc_test.go Normal file
View File

@ -0,0 +1,7 @@
package rpc
import "testing"
func TestRpc(t *testing.T) {
}