Note - Message variable is not retaining data after calling promisified functions. Callback is giving null array.
Code -
'use strict'; const Promise = require('bluebird'); let _connectResolve, _connectReject, onConnected = new Promise((resolve, reject) => { _connectResolve = resolve; _connectReject = reject; }), redis = require("redis"), redisClient = redis.createClient({ host: 'localhost', port: 6379 }); Promise.promisifyAll(redis.RedisClient.prototype);
redisClient.on('connect', _connectResolve);
const results = Promise.all([
'it/0I0g2I3D312s192u0U3k/10es.zip',
'items/25210B0c0Q1L3u0X462g/10ges.zip',
'items/2x0n440V1A1n3x1y0f1K/Fs.zip',
'items/2l023931u0w1S2a3j/es.zip',
'items/2O2x212i3t0B2h/es.zip',
]);
var message = [];
var a = Promise.promisify(function(callback) {
results.map(function(result) {
redisClient.getAsync(result).then(function(reply) {
if (reply == null) {
message.push({
"key": result,
"bucket_name": 'dsdds'
});
}
//console.log(message);
});
callback(null, message);
});
});
onConnected.then(() => {
Promise.resolve(a()).then(function(message) {
console.log(message);
});
});
Output - message is undefined
via Harsh Loomba
No comments:
Post a Comment