async / await

最后更新于:2022-04-02 03:27:40

[TOC] ## async/await 同步 ``` async getBooksAndAuthor(authorId){ const bookPromise = bookModel.fetchAll(); const authorPromise = authorModel.fetch(authorId); const book = await bookPromise; const author = await authorPromise; return { author, books:book.filter(book=>book.authorId === authorId), } } ``` ## async/await 异步 执行 fetch 函数 ``` async function mount() { const result = await Promise.all( fetch('a.json'), fetch('b.json'), fetch('c.json') ); render(...result); } ```
';