papercut icon indicating copy to clipboard operation
papercut copied to clipboard

Process returns unexpected results when run from async.parallel

Open jesseclark opened this issue 12 years ago • 1 comments

I am iterating over a set of images and using async.parralel and the hash of image urls in the callback from process contains urls from many different calls to process:

  Schema.process name, path, (err, images)->
    console.log "processPhoto images: ", _.prettyPrint(images)

-> 
2013-11-14T18:03:27.503Z - debug: processPhoto images:  {
  "avatar-icon": "https://s3.amazonaws.com/mw-development/impact-avatar-icon.jpg",
  "avatar-column": "https://s3.amazonaws.com/mw-development/impact-avatar-column.jpg",
  "avatar-card": "https://s3.amazonaws.com/mw-development/team-avatar-card.jpg",
  "large": "https://s3.amazonaws.com/mw-development/city-large.jpg"
}

In this example I would expect the urls to all contain 'impact' and not 'team' or 'city'

jesseclark avatar Nov 14 '13 19:11 jesseclark

@jesseclark You're right. It appears an instance of an uploader saves its results in itself. A workaround for now, is to instantiate a new uploader every time you upload. i.e.

async.parallel, [
  (done) ->
    uploader = new Uploader()
    uploader.process name, path, (err, images)->
      console.log "processPhoto images: ", _.prettyPrint(images)
      done()
  , ...
]

I can work on a pull request to fix this if necessary.

kennethklee avatar Aug 13 '14 14:08 kennethklee