0

I am using the co library with node-mysql2.

 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;
 });

This is used as

 newActivityCount()
   .then(..something)
   .catch(err => { throw err;});

The following error is throw :

You may only yield a function, promise, generator, array, or object, but the following object was passed: "undefined"

This is how pool is defined:

// 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;

HOWEVER, if I change line 5 above from

 yield conn.release()  to  conn.release()

i.e if I remove the 'yield' keyword, things work fine.

As per the author :

He does recommend using yield conn.end(), I am worried that if I don't 'yield' there it, I may be messing something up.

Any clues what I am missing here ?

MANISH KUMAR CHOUDHARY
  • 3,144
  • 2
  • 20
  • 30
runtimeZero
  • 22,318
  • 19
  • 63
  • 115
  • 1
    If `conn.release` does not return a promise, there's nothing asynchronous that you would need to `yield`. Probably the author of `node-mysql2` either didn't test the code in his docs, or he used a version of `co` that ignored `undefined` values. – Bergi Sep 28 '16 at 16:52
  • You should open an issue in the linked repo to fix the docs. Or fix the bug in `release`, whichever it is. – Bergi Sep 28 '16 at 16:53
  • You are right conn.release() does not return a promise. I will open a request on the repo – runtimeZero Sep 28 '16 at 16:54

0 Answers0