當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript grpc.invoke方法代碼示例

本文整理匯總了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();
          }
        });
      });
開發者ID:mwitkow,項目名稱:grpc-browser-compat,代碼行數:32,代碼來源:invoke.spec.ts

示例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");
      });
開發者ID:mwitkow,項目名稱:grpc-browser-compat,代碼行數:33,代碼來源:cancellation.spec.ts

示例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.");
開發者ID:mwitkow,項目名稱:grpc-browser-compat,代碼行數:17,代碼來源:invoke.spec.ts


注:本文中的@improbable-eng/grpc-web.grpc.invoke方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。