本文整理汇总了TypeScript中@improbable-eng/grpc-web.grpc.invoke方法的典型用法代码示例。如果您正苦于以下问题:TypeScript grpc.invoke方法的具体用法?TypeScript grpc.invoke怎么用?TypeScript grpc.invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@improbable-eng/grpc-web.grpc
的用法示例。
在下文中一共展示了grpc.invoke方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("should report failure for a trailers-only response", (done) => {
let didGetOnHeaders = false;
let didGetOnMessage = false;
const ping = new PingRequest();
grpc.invoke(FailService.NonExistant, { // The test server hasn't registered this service, so it should return an error
debug: DEBUG,
transport: transport,
request: ping,
host: emptyHost,
onHeaders: (headers: grpc.Metadata) => {
DEBUG && debug("headers", headers);
didGetOnHeaders = true;
assert.deepEqual(headers.get("grpc-status"), ["12"]);
assert.deepEqual(headers.get("grpc-message"), ["unknown service improbable.grpcweb.test.FailService"]);
},
onMessage: (message: Empty) => {
didGetOnMessage = true;
},
onEnd: (status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
assert.strictEqual(statusMessage, "unknown service improbable.grpcweb.test.FailService");
assert.strictEqual(status, 12);
assert.deepEqual(trailers.get("grpc-status"), ["12"]);
assert.deepEqual(trailers.get("grpc-message"), ["unknown service improbable.grpcweb.test.FailService"]);
assert.ok(didGetOnHeaders);
assert.ok(!didGetOnMessage);
done();
}
});
});
示例2: it
it("should allow the caller to abort an rpc before it completes", () => {
let transportCancelFuncInvoked = false;
const cancellationSpyTransport = () => {
return {
sendMessage: () => {
},
finishSend() {
},
start: () => {
},
cancel: () => {
transportCancelFuncInvoked = true;
},
}
};
const ping = new PingRequest();
ping.setValue("hello world");
const reqObj = grpc.invoke(TestService.Ping, {
debug: DEBUG,
request: ping,
host: testHostUrl,
transport: cancellationSpyTransport,
onEnd: (status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
},
});
reqObj.close();
assert.equal(transportCancelFuncInvoked, true, "transport's cancel func must be invoked");
});
示例3: debug
assert.throw(() => {
grpc.invoke(TestService.PingStream, {
debug: DEBUG,
transport: transport,
request: ping,
host: testHostUrl,
onHeaders: (headers: grpc.Metadata) => {
DEBUG && debug("headers", headers);
},
onMessage: (message: PingResponse) => {
DEBUG && debug("message", message);
},
onEnd: (status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
DEBUG && debug("status", status, "statusMessage", statusMessage);
}
})
}, ".invoke cannot be used with client-streaming methods. Use .client instead.");