本文整理匯總了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.");