-
-
Notifications
You must be signed in to change notification settings - Fork 232
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 改写回调地狱 #144
Comments
方式一:promise写法 function myPromise(time, context){
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(context);
resolve()
}, time);
})
}
// promise写法
myPromise(1000, 111)
.then(() => {
return myPromise(2000, 222);
})
.then(() => {
return myPromise(3000, 333);
}) 方式二: function myPromise(time, context){
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(context);
resolve()
}, time);
})
}
// async await写法
async function fun(){
await myPromise(1000,111);
await myPromise(2000,222);
await myPromise(3000,333);
}
fun(); |
|
const p = new Promise(resolve => { p.then(() => { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: