ravi yadav
ravi yadav

Reputation: 1

Getting Promise instead of ZoneAwarePromise

I had written below code could anyone help how to get Promise instead of ZoneAwarePromise

MyFunction(): Promise < any > () {
    let promise = new Promise((resolve) => {
        if (this.domainServerCache
            && (this.domainServerCache.domainFqdn === selectedFqdn)) {
            resolve(this.domainServerCache);
        } else if (selectedFqdn) {
            const url = `drarest/domains/get?domainFqdn=${selectedFqdn}`;
            this.http.post < any > (url, something).toPromise().then(
                (resp) => {
                    console.log('result', resp);                            
                    this.loadDomainSubject
                        .next(resp.domain.domainAdminsGroupPath);
                    this.domainServerCache = {
                        'domainFqdn': selectedFqdn,
                        ...resp
                    };
                    this.loadDomainSubject.complete();
                    resolve(this.domainServerCache);
                }
            );
        }
    });
    console.log(promise);
    return promise;
}

Upvotes: 0

Views: 405

Answers (1)

ErxrilOwl
ErxrilOwl

Reputation: 79

I think there is a better way to rewrite this

MyFunction() {
    return new Promise((resolve) => {
        if (this.domainServerCache && (this.domainServerCache.domainFqdn === selectedFqdn)) { 
            resolve(this.domainServerCache); 
        } else if (selectedFqdn) {
            const url = `drarest/domains/get?domainFqdn=${selectedFqdn}`;
            this.http.post<any>(url, something).toPromise().then(
                (resp) => {
                    console.log('result', resp);
                    this.loadDomainSubject.next(resp.domain.domainAdminsGroupPath);
                    this.domainServerCache = {'domainFqdn': selectedFqdn, ...resp};
                    this.loadDomainSubject.complete();
                    resolve(this.domainServerCache);
                }
            );
        }
    })
}

Upvotes: 1

Related Questions