I want to run different remote procedure on different servers without waiting for a reply from server. and as a server completes the procedure I want to have reply at the client. Can it be possible to do with grpc golang?
I want to implement a blockchain network and I want to ask different peers to execute a transaction but I don't want to wait until one peer provides the output of execution and then I move to other peer.
In other word I want to broadcast the execution of procedure and then have all the answers as execution is being done.
I tried the common methods for connecting client and server but it waits for the response from the server. it will increase the time when execution needs to be done on more peers.
You can use
go func(){}()
to do async jobs, and you can easy control async tasks with sync built-in package or use channels to control or sync tasks with it.
Just simply do the Client-streaming in gRPC Client send the message again and again when he send all the data
// add stream keyword when use in client side streaming
rpc HeavyLoadData(stream P2PMessages) returns (P2PMessages);
And you can also use bi-directional if you want in continuity
message P2PMessages{
string anything = 1;
}
rpc Messages(stream P2PMessages) returns (stream P2PMessages){};
And If you want to do something which has to complete and then you want to send data use lock
var lock = &sync.RWMutex{}
// it will lock until your logic completes
fun test(){
lock.RLock()
defer lock.RUnlock()
//do something your logic
}
You can also use this if you have multiple clients make a client and want to send data when complete your logic used
First create client map
var clients = make(map[string]string)
//then use the threading in go
go func(){
// maintain here all your client when you want to send the data to whom
}()