I just got my interview results back from a company called Canva. One of the feedback was that I was supposed to use Promise chaining in the following code. I am unable to comprehend how to do any chaining when there is only one Promise involved ( aTeam.setTeam()
returns a Promise)
getTeam(teamId){
return new Promise((resolve, reject) => {
// we first scan to see if the team has been initialized already. if so, we resolve immediately
if(this.teams[teamId]) return resolve(this.teams[teamId]);
// if not, we create a new Team, cache it, and issue a request to the server to set it
let aTeam = new Team(this,teamId); this.teams[teamId] = aTeam;
aTeam.setTeam().then(()=>resolve(aTeam)).catch((err)=>reject(err));
})
}
Please advise me how would I do Promise chaining here.
My complete code is at Canva's Tournament Challenge interview question.