Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

71.当async/await遇到遍历 #71

Open
wqjiao opened this issue Jan 26, 2021 · 0 comments
Open

71.当async/await遇到遍历 #71

wqjiao opened this issue Jan 26, 2021 · 0 comments

Comments

@wqjiao
Copy link
Owner

wqjiao commented Jan 26, 2021

  • for...of
async function getRequest() {
    let all = [];

    for (let item of data) {
        let res = await doSomething(item);
        all.push({id: item, res});
    }

    console.log('complete:', all);
}
  • Promise.all
async function getRequest() {
    let all = await Promise.all(
        data.map(async item => {
            let res = await doSomething(item);
            return {id: item, res};
        })
    );

    console.log('complete:', all);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant