Setting timeouts for grpc functions in node js

You can also set rpc deadline as:

function getRPCDeadline(rpcType) {

    timeAllowed = 5000
    switch(rpcType) {

        case 1:
            timeAllowed = 5000  // LIGHT RPC
            break

        case 2 :
            timeAllowed = 7000  // HEAVY RPC
            break

        default :
            console.log("Invalid RPC Type: Using Default Timeout")

    }

    return new Date( Date.now() + timeAllowed )

}

And then use this function while calling any rpc:

var deadline = getRPCDeadline(1)

grpcClient.hello({message: "abc"},{deadline: deadline}, function(err, response) {
    console.log(err)
    console.log(response)
});

Ok seems like got it working with the below code:

var timeout_in_seconds = 5
var timeout = new Date().setSeconds(new Date().getSeconds() + timeout_in_seconds)

grpcClient.hello({message: "abc"},{deadline: timeout}, function(err, response) {
    console.log(err)
    console.log(response)
});

Tags:

Node.Js

Grpc