Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import { Observable } from 'rxjs';
import { finalize, share } from 'rxjs/operators';
export function ReusePendingObservable() {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
const pendingObservablePropertyName = `__pendingObservable${propertyKey}`;
target[pendingObservablePropertyName] = null;
descriptor.value = function (...args: any[]) {
if (!target[pendingObservablePropertyName]) {
const result: Observable<any> = originalMethod.apply(this, args);
target[pendingObservablePropertyName] = result.pipe(finalize(() => target[pendingObservablePropertyName] = null), share());
return target[pendingObservablePropertyName];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.