jsonPipeDispatcher.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.JsonPipeDispatcher = void 0;
  6. var _dispatcher = require("./dispatcher");
  7. var _utils = require("../../utils");
  8. var _errors = require("../errors");
  9. /**
  10. * Copyright (c) Microsoft Corporation.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the 'License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. class JsonPipeDispatcher extends _dispatcher.Dispatcher {
  25. constructor(scope) {
  26. super(scope, {
  27. guid: 'jsonPipe@' + (0, _utils.createGuid)()
  28. }, 'JsonPipe', {});
  29. this._type_JsonPipe = true;
  30. }
  31. async send(params) {
  32. this.emit('message', params.message);
  33. }
  34. async close() {
  35. this.emit('close');
  36. if (!this._disposed) {
  37. this._dispatchEvent('closed', {});
  38. this._dispose();
  39. }
  40. }
  41. dispatch(message) {
  42. if (!this._disposed) this._dispatchEvent('message', {
  43. message
  44. });
  45. }
  46. wasClosed(error) {
  47. if (!this._disposed) {
  48. const params = error ? {
  49. error: (0, _errors.serializeError)(error)
  50. } : {};
  51. this._dispatchEvent('closed', params);
  52. this._dispose();
  53. }
  54. }
  55. dispose() {
  56. this._dispose();
  57. }
  58. }
  59. exports.JsonPipeDispatcher = JsonPipeDispatcher;