UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

48 lines (46 loc) 1.37 kB
/** * Helper class for managing rxjs objects that exist for the lifetime of their consumer. */ export class RxjsLifetimeManager { /** * Container for active subscriptions that should be cleaned up in the OnDestroy call. */ subscriptions = []; /** * Container for active subscriptions that should be cleaned up in the OnDestroy call. */ subjects = []; /** * Adds rxjs subscriptions to this lifetime manager */ addSubscriptions(...subscriptions) { subscriptions.forEach(subscription => { this.subscriptions.push(subscription); }); } /** * Adds subjects to this lifetime manager */ addSubjects(...subjects) { subjects.forEach(subject => { this.subjects.push(subject); }); } /** * Disposes this instance freeing any resources consumed by it. * Unsubscribes all subscriptions and completes all subjects. */ dispose() { this.subjects.forEach((subject) => { if (subject && !subject.closed) { subject.complete(); } }); this.subscriptions.forEach((subscription) => { if (subscription && !subscription.closed) { subscription.unsubscribe(); } }); } } //# sourceMappingURL=rxjs-lifetime-manager.js.map