node.js - nodejs 7 中的async,await到底应该怎么用?
大家讲道理
大家讲道理 2017-04-17 15:26:08
0
1
539

我写的这个函数:

var mysql=require('promise-mysql');

var pool=mysql.createPool({});

async function query() {
    let rows= await pool.query('select * from test');
    
    return rows;
}



满以为会返回真正的记录,结果返回的还是一个promise对象,难道nodejs真的不能实现像java一样的同步代码了吗?
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
PHPzhong

async will definitely return Promise. Adding await will return the direct result. However, await can only appear in async function...

So, the innermost async function must return a Promise (or a direct quantity, which will be encapsulated into a Promise), and the outermost layer must also get a Promise.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template