-
-
Notifications
You must be signed in to change notification settings - Fork 241
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串行 #152
Comments
Promise+async+await |
//Promise串行
async function serialPromise(taskarr) {
let res = [];
for (const task of taskarr) {
try {
res.push(await task());
} catch (err) {
res.push(null);
}
}
return res;
} |
// 使用reduce function runPromiseByQueue(myPromises) {
return myPromises.reduce((prev, next) => {
return prev.then(() => next());
}, Promise.resolve());
}
const createPromise = (time, id) => () => new Promise(resolve => {
setTimeout(() => {
resolve(time);
console.log("promise", id);
}, time);
});
runPromiseByQueue().then((res) => {
console.log(res);
}); |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: