Commit d439800c authored by Boris Mühmer's avatar Boris Mühmer
Browse files

added some client wrappers... async is not async yet

parent 26642ade
Loading
Loading
Loading
Loading
Loading
+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, &quotient)
	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
}