Skip to content

Commit

Permalink
fix(promises): handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kKen94 committed Aug 18, 2020
1 parent 8282af3 commit 9e6f87a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion projects/lib/src/lib/bar/bar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BarService {
clearInterval(this.interval);
}

complete(): Promise<unknown> {
async complete(): Promise<unknown> {
this.set(99);
return new Promise(resolve => {
setTimeout(() => {
Expand Down
26 changes: 18 additions & 8 deletions projects/lib/src/lib/ngx-progress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ export class NgxProgressService {
this.progressCount--;
}
if (this.progressCount === 0) {
this.barService.complete().then(() => {
this.isStarted = false;
this.endEmitter.next();
});
this.barService
.complete()
.then(() => {
this.isStarted = false;
this.endEmitter.next();
})
.catch(error => {
throw new Error(error);
});
}
}

Expand All @@ -76,10 +81,15 @@ export class NgxProgressService {
* Force the end of the progress
*/
terminate(): void {
this.barService.complete().then(() => {
this.isStarted = false;
this.endEmitter.next();
});
this.barService
.complete()
.then(() => {
this.isStarted = false;
this.endEmitter.next();
})
.catch(error => {
throw new Error(error);
});
}

/**
Expand Down

0 comments on commit 9e6f87a

Please sign in to comment.