Back in the AngularJS 1.* days, I used to have this code snippet to refresh the auth-token:
...
if (!refreshTokenInProgress) {
refreshTokenInProgress = AuthService.refreshToken();
}
$q.when(refreshTokenInProgress, function () {
refreshTokenInProgress = null;
// re-send requests with error
...
}, function () {
// logout if refresh token rejected
refreshTokenInProgress = null;
...
});
...
How do I convert this code to use Observables in Angular 2?
I'm stumped because this approach doesn't seem to be working:
if (!refreshTokenInProgress) {
refreshTokenInProgress = AuthService.refreshToken().subscribe();
}
Observable.forkJoin([this.refreshTokenInProgress]).subscribe(
success => this.refreshTokenInProgress = null
);
What is the equivalent of $q.when
in RxJs?