Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Subscription add function do with Promise's resolve call-back

I can see in GitHub project angular-10-signup-verification-boilerplate the following snippet:

export function appInitializer(accountService: AccountService) {
    return () => new Promise(resolve => {
        // attempt to refresh token on app start up to auto authenticate
        accountService.refreshToken()
            .subscribe()
            .add(resolve);
    });
}

I was wondering if somebody could explain what is the meaning of add function with parameter resolve. Documentation says that add function is for adding additional subscribers so they can be unsubscribed in one go.

like image 791
janci Avatar asked Nov 27 '25 18:11

janci


1 Answers

The add method of the subscription returned from subscribe will run when the subscription completes (and is subsequently unsubscribed)

In your example the resolve will be called when the refreshToken completes. When the Promise resolves and the APP_INITIALIZER (which is waiting for the promise to resolve) will continue

Note: I've never seen it used before - the more common approach is to use the subscribe next/error/complete functions or a finalize operator

like image 90
Drenai Avatar answered Nov 30 '25 07:11

Drenai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!