当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript grpc.client方法代码示例

本文整理汇总了TypeScript中@improbable-eng/grpc-web.grpc.client方法的典型用法代码示例。如果您正苦于以下问题:TypeScript grpc.client方法的具体用法?TypeScript grpc.client怎么用?TypeScript grpc.client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@improbable-eng/grpc-web.grpc的用法示例。


在下文中一共展示了grpc.client方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

        it(`should not suppress exceptions`, (done) => {
          const ping = new PingRequest();
          ping.setValue("hello world");

          const client = grpc.client(TestService.Ping, {
            debug: DEBUG,
            transport: transport,
            host: testHostUrl,
          });
          client.onHeaders((headers: grpc.Metadata) => {
            throw new Error("onHeaders exception");
          });
          client.onMessage((message: PingResponse) => {
            throw new Error("onMessage exception");
          });
          client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
            setTimeout(() => {
              uncaughtHandler.detach();
              const exceptionsCaught = uncaughtHandler.getMessages();
              assert.lengthOf(exceptionsCaught, 3);
              assert.include(exceptionsCaught[0], "onHeaders exception");
              assert.include(exceptionsCaught[1], "onMessage exception");
              assert.include(exceptionsCaught[2], "onEnd exception");
              done();
            }, 100);
            throw new Error("onEnd exception");
          });
          client.start();
          client.send(ping);
        });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:30,代码来源:client.spec.ts

示例2: it

          it("should make a bidirectional request that is terminated by the server", (done) => {
            let didGetOnHeaders = false;
            let didGetOnMessage = false;

            let counter = 1;
            let lastMessage = `helloworld:${counter}`;
            const ping = new PingRequest();
            ping.setSendHeaders(withHeaders);
            ping.setSendTrailers(withTrailers);
            ping.setValue(lastMessage);

            const client = grpc.client(TestService.PingPongBidi, {
              debug: DEBUG,
              host: testHostUrl,
              transport: grpc.WebsocketTransport(),
            });
            client.onHeaders((headers: grpc.Metadata) => {
              DEBUG && debug("headers", headers);
              didGetOnHeaders = true;
              if (withHeaders) {
                assert.deepEqual(headers.get("HeaderTestKey1"), ["ServerValue1"]);
                assert.deepEqual(headers.get("HeaderTestKey2"), ["ServerValue2"]);
              }
            });
            client.onMessage((message: PingResponse) => {
              assert.ok(message instanceof PingResponse);
              assert.deepEqual(message.getValue(), lastMessage);

              if (counter === 10) {
                const ping = new PingRequest();
                ping.setFailureType(PingRequest.FailureType.CODE);
                ping.setErrorCodeReturned(grpc.Code.OK);
                client.send(ping);
              } else {
                counter++;
                lastMessage = `helloworld:${counter}`;
                const ping = new PingRequest();
                ping.setValue(lastMessage);
                client.send(ping);
              }
            });
            client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
              DEBUG && debug("status", status, "statusMessage", statusMessage);
              assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
              assert.strictEqual(statusMessage, "", "expected no message");
              if (withTrailers) {
                assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
                assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
              }
              assert.ok(didGetOnHeaders, "didGetOnHeaders");

              assert.equal(counter, 10, "counter should have been incremented to 10");
              done();
            });
            client.start();

            // send initial message
            client.send(ping);
          });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:59,代码来源:client.websocket.spec.ts

示例3:

 assert.throw(() => {
   const client = grpc.client(TestService.Ping, {
     debug: DEBUG,
     transport: transport,
     host: testHostUrl,
   });
   client.send(ping);
 }, "Client not started - .start() must be called before .send()");
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:8,代码来源:client.spec.ts


注:本文中的@improbable-eng/grpc-web.grpc.client方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。