index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. const assert = require('assert');
  3. const is = require('is-type-of');
  4. const cluster = require('./lib');
  5. const symbols = require('./lib/symbol');
  6. const APIClientBase = require('./lib/api_client');
  7. /**
  8. * Create an Wrapper
  9. *
  10. * @param {Function} clientClass - client class
  11. * @param {Object} options - wrapper options
  12. * @return {ClientWrapper} wrapper
  13. */
  14. module.exports = cluster;
  15. /**
  16. * Close a ClusterClient
  17. *
  18. * @param {Object} client - ClusterClient instance to be closed
  19. * @return {Promise} returns a promise which will be resolved after fully closed
  20. */
  21. module.exports.close = client => {
  22. assert(is.function(client[symbols.close]), '[cluster#close] client should be instanceof ClusterClient');
  23. return client[symbols.close]();
  24. };
  25. /**
  26. * API Client SuperClass
  27. *
  28. * @example
  29. * ---------------------------------------------
  30. * class ClusterClient extends APIClientBase {
  31. * get DataClient() {
  32. * return require('./supports/client');
  33. * }
  34. * get delegates() {
  35. * return {
  36. * unPublish: 'invokeOneway',
  37. * };
  38. * }
  39. * get clusterOptions() {
  40. * return {
  41. * responseTimeout: 1000,
  42. * port,
  43. * };
  44. * }
  45. * subscribe(...args) {
  46. * return this._client.subscribe(...args);
  47. * }
  48. * unSubscribe(...args) {
  49. * return this._client.unSubscribe(...args);
  50. * }
  51. * publish(...args) {
  52. * return this._client.publish(...args);
  53. * }
  54. * unPublish(...args) {
  55. * return this._client.unPublish(...args);
  56. * }
  57. * close() {
  58. * return this._client.close();
  59. * }
  60. * }
  61. */
  62. module.exports.APIClientBase = APIClientBase;