Skip to content

Commit

Permalink
change observable to use pipe finalize instead of subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuzuld committed Aug 5, 2024
1 parent 51aad2f commit 3120747
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-busy2",
"version": "20.1.0",
"version": "20.1.1",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-busy2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-busy2",
"version": "20.1.0",
"version": "20.1.1",
"license": "MIT",
"homepage": "https://tiberiuzuld.github.io/angular-busy/",
"bugs": {
Expand Down
16 changes: 2 additions & 14 deletions projects/angular-busy2/src/lib/cgBusy.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable, Subscription } from 'rxjs';
import {finalize, Observable, Subscription} from 'rxjs';

export interface TrackerOptions {
minDuration: number;
Expand Down Expand Up @@ -33,15 +33,7 @@ export class CgBusyService {
} else if (promiseThing.then) {
promiseThing.then(callback, callback);
} else if (promiseThing instanceof Observable) {
let subscription: Subscription;
const cc = () => {
if (subscription) {
subscription.unsubscribe();
}
callback();
};
subscription = promiseThing.subscribe({error: cc, complete: cc});
this.subscriptions.push(subscription);
promiseThing.pipe(finalize(callback));
} else if (promiseThing instanceof Subscription) {
promiseThing.add(callback);
} else {
Expand Down Expand Up @@ -131,10 +123,6 @@ export class CgBusyService {
this.durationPromise = null;
}
this.promises = [];
this.subscriptions.forEach((subscription) => {
subscription.unsubscribe();
});
this.subscriptions = [];
this.detectChanges = null;
}
}

0 comments on commit 3120747

Please sign in to comment.