Skip to content

Instantly share code, notes, and snippets.

@jevets
Last active December 26, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jevets/7219049 to your computer and use it in GitHub Desktop.
Save jevets/7219049 to your computer and use it in GitHub Desktop.
Grunt task recurse files async - help needed
/**
* I can't figure out why this doesn't work.
*
* I've tried using async, but there's no way to know when the exif stuff is done.
*
* Please help me understand what I'm doing wrong.
*/
var util = require('util');
var ExifImage = require('exif').ExifImage;
// src/photos contains several photos with exif data
grunt.registerTask('default', function() {
grunt.file.expand('src/photos/*.jpg').forEach(function(el, i, array) {
// this gets output to the console
grunt.log.writeln('Attempt to get exif data for ' + el);
new ExifImage({ image: 'src/photos/' + el }, function(err, exifData) {
// but neither of these do
if (err) grunt.log.writeln('Error: ' + err.message);
grunt.log.writeln(util.inspect(exifData));
// nor does this
grunt.log.writeln('Inside new ExifImage');
});
});
});
@shama
Copy link

shama commented Oct 29, 2013

grunt.registerTask('default', function() {
  var done = this.async();

  var files = grunt.file.expand('src/photos/*.jpg');
  grunt.util.async.eachSeries(files, function(el, next) {
    grunt.log.writeln('Attempt to get exif data for ' + el);
    new ExifImage({ image: 'src/photos/' + el }, function(err, exifData) {
      // but neither of these do
      if (err) grunt.log.writeln('Error: ' + err.message);
      grunt.log.writeln(util.inspect(exifData));
      // nor does this
      grunt.log.writeln('Inside new ExifImage');

      // Call this to move onto the next image
      next();
    });
  }, done); // done is called when all have completed

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment