rpc.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. /**
  3. * Streaming RPC helpers.
  4. * @namespace
  5. */
  6. var rpc = exports;
  7. /**
  8. * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
  9. * @typedef RPCImpl
  10. * @type {function}
  11. * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
  12. * @param {Uint8Array} requestData Request data
  13. * @param {RPCImplCallback} callback Callback function
  14. * @returns {undefined}
  15. * @example
  16. * function rpcImpl(method, requestData, callback) {
  17. * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
  18. * throw Error("no such method");
  19. * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
  20. * callback(err, responseData);
  21. * });
  22. * }
  23. */
  24. /**
  25. * Node-style callback as used by {@link RPCImpl}.
  26. * @typedef RPCImplCallback
  27. * @type {function}
  28. * @param {Error|null} error Error, if any, otherwise `null`
  29. * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
  30. * @returns {undefined}
  31. */
  32. rpc.Service = require("./rpc/service");