Skip to content

Instantly share code, notes, and snippets.

@vojtatranta
Created May 3, 2016 21:53
Show Gist options
  • Save vojtatranta/7316d8811e3b9f7808d3d8684645d737 to your computer and use it in GitHub Desktop.
Save vojtatranta/7316d8811e3b9f7808d3d8684645d737 to your computer and use it in GitHub Desktop.
Promise hell
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