mercredi 27 mai 2015

Use of async in Amazon Lambda example?

I'm reviewing Amazon Lambda's example code for resizing images in S3 buckets. Example code (snipped for clarity):

// Download the image from S3, transform, and upload to a different S3 bucket.
async.waterfall([
  function download(next) {
    // Download the image from S3 into a buffer.
    s3.getObject({Bucket: srcBucket, Key: srcKey}, next);
  },
  function tranform(response, next) {
    gm(response.Body).size(function(err, size) {
      // do resize with image magic
    }
  }
]);
//... more handling code

...shows they are using async waterfall. However, each of these ordered steps seems to rely on the results of the previous function. So in essence, this is a sequential operation.

What is the benefit of using async waterfall here? Is this something to do with Lambda's execution engine at Amazon, or just a sensible design decision in node?




Aucun commentaire:

Enregistrer un commentaire