@Yoyo31 wrote:
Hey all!
I hope you can help me, because I have some problems with the sequence of my functions (Firebase)
Note that I am a newbie (started development 3 weeks ago) and sorry for my bad english …As you can see on the code below, I try to use async function with .then method. My function calls DB on Firebase, so some functions take longer to complete tasks.
I don’t understand why my function: SearchOrg() is finished after my function : Invitation() … while I specify to continue the code in .then …
I passed long time to try other methods as : await or Promise with function(resolve, reject) … but nothing succeeded.async SearchOrg () { this.afDB.list('Attente/' + this.userID + '/Amis').snapshotChanges(['child_added', 'child_removed']).subscribe(actions => { this.testUser = []; console.log(this.userID); actions.forEach(action => { this.testUser.push(action.key); // payload.exportVal().Organisateur); }); console.log(this.testUser); // Displayed Last }); return this.testUser; } async Invitation() { const test = await this.SearchOrg().then(() => { console.log(test); // Displayed First if (test !== ' ') { this.MasterFlag = true; this.presentLoadingWithOptions(); } else { this.Inviter = []; this.MasterFlag = false; this.afDB.list('Attente/' + this.userID + '/Organisateur').snapshotChanges(['child_added', 'child_removed']) .subscribe(actions => { actions.forEach(action => { this.Inviter.push(action.payload.exportVal().Organisateur); }); }); console.log(this.Inviter); // Displayed second } }); }
Many thanks for helps
BR
Yoann
Posts: 2
Participants: 2