我写的这个函数:
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一样的同步代码了吗?
PHPz2017-04-17 15:28:08
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.