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一样的同步代码了吗?
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.
async
will definitely return Promise. Addingawait
will return the direct result. However,await
can only appear inasync 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.