Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

using.js 1.0KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Observable_1 = require("../Observable");
  4. var from_1 = require("./from");
  5. var empty_1 = require("./empty");
  6. function using(resourceFactory, observableFactory) {
  7. return new Observable_1.Observable(function (subscriber) {
  8. var resource;
  9. try {
  10. resource = resourceFactory();
  11. }
  12. catch (err) {
  13. subscriber.error(err);
  14. return undefined;
  15. }
  16. var result;
  17. try {
  18. result = observableFactory(resource);
  19. }
  20. catch (err) {
  21. subscriber.error(err);
  22. return undefined;
  23. }
  24. var source = result ? from_1.from(result) : empty_1.EMPTY;
  25. var subscription = source.subscribe(subscriber);
  26. return function () {
  27. subscription.unsubscribe();
  28. if (resource) {
  29. resource.unsubscribe();
  30. }
  31. };
  32. });
  33. }
  34. exports.using = using;
  35. //# sourceMappingURL=using.js.map