wishthis/node_modules/rxjs/_esm2015/internal/observable/using.js
2022-01-21 09:28:41 +01:00

32 lines
No EOL
898 B
JavaScript

import { Observable } from '../Observable';
import { from } from './from';
import { EMPTY } from './empty';
export function using(resourceFactory, observableFactory) {
return new Observable(subscriber => {
let resource;
try {
resource = resourceFactory();
}
catch (err) {
subscriber.error(err);
return undefined;
}
let result;
try {
result = observableFactory(resource);
}
catch (err) {
subscriber.error(err);
return undefined;
}
const source = result ? from(result) : EMPTY;
const subscription = source.subscribe(subscriber);
return () => {
subscription.unsubscribe();
if (resource) {
resource.unsubscribe();
}
};
});
}
//# sourceMappingURL=using.js.map