We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
async1
await
Promise
pending
.then
如果在一个 Promise 前使用了 await, 那么一定要 resolve('OK') / reject('Error') 不然会一直 await , 阻挡后面语句的执行.
async function async1() { console.log('async1 start') await new Promise((resolve) => { console.log('promise1') // ✅✅ 此处需要 reslove }) console.log('async1 success') return 'async1 end' } console.log('srcipt start') async1().then((res) => console.log(res)) console.log('srcipt end') /** * srcipt start * async1 start * promise1 * srcipt end */
async function async1() { console.log('async1 start') await new Promise((resolve) => { console.log('promise1') resolve('value in async1 await') // 这一行的结果没有被接收 }) console.log('async1 success') return 'async1 end' // 直接返回了字符串 .then(res) 中的 res的值 } console.log('srcipt start') async1().then((res) => console.log(res)) console.log('srcipt end') /** * srcipt start * async1 start * promise1 * srcipt end * async1 success * async1 end */
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Promise 5 - 5
async1
中await
后面的Promise
是没有返回值的, 也就是它的状态始终是pending
状态, 因此相当于一直在await
,await
,await
却始终没有响应.await
之后的内容是不会执行的, 也包括async1
后面的.then
.如果在一个 Promise 前使用了 await, 那么一定要 resolve('OK') / reject('Error') 不然会一直 await , 阻挡后面语句的执行.
在async1的await后设置返回
The text was updated successfully, but these errors were encountered: