Loading pkg/rpcexamplelib/client.go 0 → 100644 +31 −0 Original line number Diff line number Diff line package rpcexamplelib import ( "net/rpc" ) // MultiplySync is a rpc wrapper for the synchronos call to Multiply. func MultiplySync(client *rpc.Client, a int, b int) (int, error) { args := &Args{A: a, B: b} var reply int err := client.Call("Arith.Multiply", args, &reply) return reply, err } // DivideSync is a rpc wrapper for the synchronos call to Divide. func DivideSync(client *rpc.Client, a int, b int) (int, int, error) { args := &Args{A: a, B: b} var quotient Quotient err := client.Call("Arith.Divide", args, "ient) return quotient.Quo, quotient.Rem, err } // DivideAsync is a apc wrapper for the asynchronos call to Divide. // TBD: this is not async, yet func DivideAsync(client *rpc.Client, a int, b int) (int, int, error) { args := &Args{A: a, B: b} quotient := new(Quotient) divCall := client.Go("Arith.Divide", args, quotient, nil) replyCall := <-divCall.Done return quotient.Quo, quotient.Rem, replyCall.Error } Loading
pkg/rpcexamplelib/client.go 0 → 100644 +31 −0 Original line number Diff line number Diff line package rpcexamplelib import ( "net/rpc" ) // MultiplySync is a rpc wrapper for the synchronos call to Multiply. func MultiplySync(client *rpc.Client, a int, b int) (int, error) { args := &Args{A: a, B: b} var reply int err := client.Call("Arith.Multiply", args, &reply) return reply, err } // DivideSync is a rpc wrapper for the synchronos call to Divide. func DivideSync(client *rpc.Client, a int, b int) (int, int, error) { args := &Args{A: a, B: b} var quotient Quotient err := client.Call("Arith.Divide", args, "ient) return quotient.Quo, quotient.Rem, err } // DivideAsync is a apc wrapper for the asynchronos call to Divide. // TBD: this is not async, yet func DivideAsync(client *rpc.Client, a int, b int) (int, int, error) { args := &Args{A: a, B: b} quotient := new(Quotient) divCall := client.Go("Arith.Divide", args, quotient, nil) replyCall := <-divCall.Done return quotient.Quo, quotient.Rem, replyCall.Error }