我正在使用带有 node-mysql2 的 co 库。
const newActivityCount = co.wrap(function *(memberId) {
var sql = "SELECT 1";
var conn = yield pool.getConnection();
var results = yield conn.execute(sql);
yield conn.release();
return results[0][0].newActivity;
});
这用作
newActivityCount()
.then(..something)
.catch(err => { throw err;});
抛出以下错误:
You may only yield a function, promise, generator, array, or object, but the following object was passed: "undefined"
池是这样定义的:
// my-connection.js
var mysql = require('mysql/promise');
var bluebird = require('bluebird);
const pool = mysql.createPool({
connectionLimit: CONFIG.mysql.connectionLimit,
host : CONFIG.mysql.host,
user : CONFIG.mysql.user,
password : CONFIG.mysql.password,
database : CONFIG.mysql.database,
Promise : bluebird
});
module.exports = pool;
但是,如果我将上面的第 5 行从
yield conn.release() to conn.release()
即,如果我删除“yield”关键字,一切正常。
根据作者:
他确实建议使用yield conn.end()
,我担心如果我不在那里“屈服”,我可能会搞砸一些事情。
任何线索我在这里缺少什么?