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


TypeScript grpc.unary方法代码示例

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


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

示例1: continueStream

            continueStream(testHostUrl, streamIdentifier, (status) => {
              DEBUG && debug("checkAbort.continueStream.status", status);

              const checkStreamClosedRequest = new CheckStreamClosedRequest();
              checkStreamClosedRequest.setStreamIdentifier(streamIdentifier);
              grpc.unary(TestUtilService.CheckStreamClosed, {
                debug: DEBUG,
                request: checkStreamClosedRequest,
                host: testHostUrl,
                onEnd: ({message}) => {
                  const closed = ( message as CheckStreamClosedResponse ).getClosed();
                  DEBUG && debug("closed", closed);
                  if (closed) {
                    done();
                  } else {
                    if (attempt >= maxAbortChecks) {
                      assert.ok(closed, `server did not observe connection closure within ${maxAbortChecks} seconds`);
                      done();
                    } else {
                      setTimeout(() => {
                        checkAbort(attempt + 1);
                      }, 1000);
                    }
                  }
                },
              })
            });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:27,代码来源:cancellation.spec.ts

示例2: it

        it(`should make a unary request`, (done) => {
          const ping = new PingRequest();
          ping.setValue("hello world");
          ping.setSendHeaders(withHeaders);
          ping.setSendTrailers(withTrailers);

          grpc.unary(TestService.Ping, {
            debug: DEBUG,
            transport: transport,
            request: ping,
            host: testHostUrl,
            onEnd: ({status, statusMessage, headers, message, trailers}) => {
              DEBUG && debug("status", status, "statusMessage", statusMessage, "headers", headers, "res", message, "trailers", trailers);
              assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
              assert.isNotOk(statusMessage, "expected no message");
              if (withHeaders) {
                assert.deepEqual(headers.get("HeaderTestKey1"), ["ServerValue1"]);
                assert.deepEqual(headers.get("HeaderTestKey2"), ["ServerValue2"]);
              }
              assert.ok(message instanceof PingResponse);
              const asPingResponse: PingResponse = message as PingResponse;
              assert.deepEqual(asPingResponse.getValue(), "hello world");
              assert.deepEqual(asPingResponse.getCounter(), 252);
              if (withTrailers) {
                assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
                assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
              }
              done();
            }
          });
        });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:31,代码来源:unary.spec.ts

示例3: debug

 assert.throw(() => {
   grpc.unary(TestService.PingStream as any as grpc.UnaryMethodDefinition<PingRequest, PingResponse>, {
     debug: DEBUG,
     transport: transport,
     request: ping,
     host: testHostUrl,
     onEnd: ({status, statusMessage, headers, message, trailers}) => {
       DEBUG && debug("status", status, "statusMessage", statusMessage, "headers", headers, "res", message, "trailers", trailers);
     }
   })
 }, ".unary cannot be used with client-streaming methods. Use .client instead.");
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:11,代码来源:unary.spec.ts

示例4: getBook

function getBook() {
  const getBookRequest = new GetBookRequest();
  getBookRequest.setIsbn(60929871);
  grpc.unary(BookService.GetBook, {
    request: getBookRequest,
    host: host,
    onEnd: res => {
      const { status, statusMessage, headers, message, trailers } = res;
      console.log("getBook.onEnd.status", status, statusMessage);
      console.log("getBook.onEnd.headers", headers);
      if (status === grpc.Code.OK && message) {
        console.log("getBook.onEnd.message", message.toObject());
      }
      console.log("getBook.onEnd.trailers", trailers);
      queryBooks();
    }
  });
}
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:18,代码来源:index.ts


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