Problem with unref
I have some code with co and unref. After call redis.info thread exit from co function.
Example:
"use strict";
const co = require("co");
const redis = require("redis");
const client = redis.createClient();
client.unref(); // PROBLEM!
client.on("error", function (err) {
throw err;
});
function callRedis() {
return new Promise((resolve, reject) => {
client.info((err, reply) => {
console.log('callback');
if (err) {
throw err;
}
resolve(reply);
});
});
}
co(function*() {
console.log('before');
let data = yield callRedis();
console.log('after'); // NO PRINT
}).catch(function (err) {
console.error(err);
});
console.log('exit');
Output:
before
end
co 4.6.0 redis 2.6.2 node v5.0.0
At a glance it looks like you're early unref is causing node to think there's no work left to do, so it exits. Node itself isn't really built to run generators to completion, you could have a while(1) loop in there for example and node would still exit
I solved the problem by removing unref and thought that it may be interesting.
I didn't look deep into the issue, but I think the problem is, that you "throw" inside a callback.
Has nothing todo with "co". Just the Promise is never fulfilled.
\Christoph
Am 22.07.2016 um 16:34 schrieb green13 [email protected]: I solved the problem by removing unref and thought that it may be interesting.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
cool cool! closing since it's just a node thing