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

串行Promise的实现 #16

Open
jindada opened this issue Jul 12, 2019 · 0 comments
Open

串行Promise的实现 #16

jindada opened this issue Jul 12, 2019 · 0 comments

Comments

@jindada
Copy link
Owner

jindada commented Jul 12, 2019

const data = [1, 2, 3, 4, 5];

const request = item => new Promise(resolve => 
  setTimeout(() => {
     console.log(item);
     resolve(item);
  }, 2000)
);

const queue = async data => {
  let result = [];
  for (let item of data) {
     result.push(await request(item));
  }
  return await result;
};

queue(data).then(data => console.log('结束', data));
@jindada jindada changed the title 串行的Promise实现 串行Promise的实现 Jul 12, 2019
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