JavaScript Promise非同步實現章節的下載顯示

來源:互聯網
上載者:User

標籤:json   順序   promise   asc   googl   res   nta   迴圈   es2017   

Links:

JavaScript Promise:簡介

1.一章一章順序地下載顯示下載顯示
使用Array.reduce()和Promise.resolve()將各章的下載及顯示作為整體串聯起來。
[下載][顯示]串聯再串聯。
promise.resolve().[then().then()].[then().then()].... => 串聯
2.各章節分別下載完成後,才再一章一章顯示
使用Array.map()將各章的下載並行起來,用Promise.all()將結果合并一處,然後再一章一章地迴圈顯示。[下載]先並聯再與[顯示]串聯
Promise.all() => 並聯
3.各章節分別下載,下載的同時按章節順序連續性地顯示。若排到的要顯示的章節未下載完才等待。
使用Array.map()將各章的下載並行起來,然後用Promise.resolve()將各章節的[顯示]串聯起來
story.chapterUrls.map(getJSON) => 並行下載
promise.resolve().[then()].[then()].[then()]

並行是通過數組的迴圈執行getJSON來順序開始的。

串列是通過promise的then來實現的,只有前一步then完成了,才做下一步then。

JavaScript Promise非同步實現章節的下載顯示

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.