async / await processing a plurality of network requests synchronization

1.async / await is based, is a further optimization of Promise, await waits for asynchronous execution is complete

                getProjectTask(id){
                    this.axios.get('/api/v1/task/' + id).then(resp=>{
                        this.allTasks.push(resp.data.data);
                    })
                },
                getAllTask(){
                    this.projectIds.forEach(id=>{
                        (async()=>{await this.getProjectTask(id)})();
                    })
                }

 

Guess you like

Origin www.cnblogs.com/jlyuan/p/11729838.html