You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var query = thunkify(pool.query)
exports.data = function(req, res) {
co(function*() {
var result = yield query('select mid, name, mtype, p.....');
var data = [];
.....
it's always wrong with undefined property, we find that because the context of query function changed, and we change the thunkify function:
function thunkify(fn,context){
assert('function' == typeof fn, 'function required');
return function(){
var args = new Array(arguments.length);
var ctx = context||this;
for(var i = 0; i < args.length; ++i) {
args[i] = arguments[i];
}
return function(done){
var called;
args.push(function(){
if (called) return;
called = true;
done.apply(null, arguments);
});
try {
fn.apply(ctx, args);
} catch (err) {
done(err);
}
}
}
};
so that we can use it like this:
var query = thunkify(pool.query, pool)
after all, we now can use thunkify with not-global function.
The text was updated successfully, but these errors were encountered:
When we use the mysql:
it's always wrong with undefined property, we find that because the context of query function changed, and we change the thunkify function:
so that we can use it like this:
after all, we now can use thunkify with not-global function.
The text was updated successfully, but these errors were encountered: