請問多個async函數(shù)塊之間如何同步的進行執(zhí)行?例子:以下兩個async函數(shù)塊如何順序進行?classExample{first;second;constructor(){}asyncgetFirstVal(){this.first=await[一個promise]}asyncgetSecondVal(){this.second=await[一個依賴于first的promise]}asyncgetOtherVal(){this.other=await[一個promise]}doSomeWork(){this.getFirstVal();this.getSecondVal();this.getOtherVal();........}}請問,怎么做才能保證doSomeWork里面的first和second這兩個異步塊順序執(zhí)行?我不想將second這一部分的邏輯寫入getFirstVal方法中,雖然這樣能獲得正確的執(zhí)行順序,因為getFirstVal可能在很多地方都會異步調(diào)用到,我想將他封裝成一個單獨的函數(shù)。請問有什么好的方法幫助我實現(xiàn)這種async塊之間的順序執(zhí)行嗎?
async函數(shù)塊之間如何同步執(zhí)行?
繁星點點滴滴
2019-05-13 13:41:26