Created
July 11, 2014 19:12
-
-
Save dtothefp/c66f527c08e77e53f03d to your computer and use it in GitHub Desktop.
node promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function readImg(path) { | |
| var deferred = Q.defer(); | |
| fs.readFile(path, function(err, original_data){ | |
| if(!err) { | |
| deferred.resolve(original_data.toString('base64')); | |
| } else { | |
| deferred.reject(err); | |
| } | |
| }); | |
| return deferred.promise; | |
| } | |
| var latestScreen = readImg(this.options.indexPath + 'img/tmp/' + pictureName); | |
| var previousScreen = readImg(this.options.indexPath + 'img/screens/' + pictureName); | |
| Q.when(latestScreen, previousScreen).done(function(latest, previous) { | |
| console.log("both resolved"); | |
| console.log(previous); | |
| gm.compare(latest, previous, function (err, isEqual, equality, raw) { | |
| if(err) console.log(err); | |
| console.log('The images are equal: %s', isEqual); | |
| }); | |
| }); |
jordangarcia
commented
Jul 11, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment