This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/rxjs/_esm2015/internal/observable/using.js

32 lines
898 B
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
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