Created
May 3, 2016 21:53
-
-
Save vojtatranta/7316d8811e3b9f7808d3d8684645d737 to your computer and use it in GitHub Desktop.
Promise hell
This file contains 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
ImageProcessor.prototype.run = function ImageProcessor_run(config) { | |
return new Promise(function(resolve, reject) { | |
// If object.size equals 0, stop process | |
if ( this.s3Object.object.size === 0 ) { | |
reject("Object size equal zero. Nothing to process."); | |
return; | |
} | |
if ( ! config.get("bucket") ) { | |
config.set("bucket", this.s3Object.bucket.name); | |
} | |
S3.getObject( | |
this.s3Object.bucket.name, | |
this.s3Object.object.key | |
) | |
.then(function(imageData) { | |
this.processImage(imageData, config) | |
.then(function(results) { | |
S3.putObjects(results) | |
.then(function(images) { | |
resolve(images); | |
}) | |
.catch(function(messages) { | |
reject(messages); | |
}); | |
}) | |
.catch(function(messages) { | |
reject(messages); | |
}); | |
}.bind(this)) | |
.catch(function(error) { | |
reject(error); | |
}); | |
}.bind(this)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment