Sunday, 7 May 2017

Bluebird Promisify execFile can't get promise to resolve

Please excuse my noobness, but why isn't this working? then() is never fired, and neither is error(). Promise seems to never resolve.

Any pointers appreciated. Thanks.

var Promise = require('bluebird');
var execFile = require('child_process').execFile;
execFile = Promise.promisify(execFile);
var IMAGE_DIR = "resources/assets/images";
var validImages = ['.jpg', '.png'];

 ... // setup omitted ... 

execFile('find', [IMAGE_DIR], function (err, stdout, stderr) {
  var images = [];
  return new Promise(function(resolve) {
    var fileList = stdout.split('\n');
    images = fileList.filter(function (image) {
      var ext = path.extname(image);
      if (validImages.indexOf(ext) > -1) {
        return image;
      }
    })
    return resolve(images);
  })
}).then(function () {
  console.log(arguments);
}).catch(console.log.bind(console));



via Simon

No comments:

Post a Comment