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
async函数就是将 Generator 函数的星号(*)替换成async,将yield替换成await,仅此而已。
async
Generator
yield
await
可以像普通函数一样执行
const asyncReadFile = async function () { const f1 = await readFile('/etc/fstab'); const f2 = await readFile('/etc/shells'); console.log(f1.toString()); console.log(f2.toString()); }; asyncReadFile() //可以像普通函数一样执行
语义化更清楚了
co模块约定,yield命令后面只能是 Thunk 函数或 Promise 对象,而async函数的await命令后面,可以是 Promise 对象和原始类型的值(数值、字符串和布尔值,但这时等同于同步操作)。
返回值是Promise对象,可以用then指定下一步操作
then
The text was updated successfully, but these errors were encountered:
No branches or pull requests
async
函数相对于Generator函数的改进:The text was updated successfully, but these errors were encountered: