有奖捉虫:云通信与企业服务文档专题,速来> HOT
InvokeOption 是 Client.invoke 执行方法过程中的可选配置。

字段

字段
类型
描述
headers?
Record<string, string[]>
请求头
timeout?
number
超时时间,单位为毫秒

样例

使用 InvokeOption 设置执行的可选配置:
export default () => {
// 建立连接
client.connect('grpcb.in:9000', { insecure: true });

// 调用方法
const rsp = client.invoke(
'addsvc.Add/Sum',
{ a: 1, b: 2 },
// 配置 InvokeOption
{
headers: {
example: ['a', 'b'],
},
timeout: 5000,
},
);
console.log(rsp.data.v); // 3

// 关闭连接
client.close();
};