{"action":"closed","issue":{"url":"https://api.github.com/repos/FAC6/facfaq/issues/5","labels_url":"https://api.github.com/repos/FAC6/facfaq/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/FAC6/facfaq/issues/5/comments","events_url":"https://api.github.com/repos/FAC6/facfaq/issues/5/events","html_url":"https://github.com/FAC6/facfaq/issues/5","id":120161668,"number":5,"title":"set of asyncs called by set of asyncs!","user":{"login":"des-des","id":12845233,"avatar_url":"https://avatars.githubusercontent.com/u/12845233?v=3","gravatar_id":"","url":"https://api.github.com/users/des-des","html_url":"https://github.com/des-des","followers_url":"https://api.github.com/users/des-des/followers","following_url":"https://api.github.com/users/des-des/following{/other_user}","gists_url":"https://api.github.com/users/des-des/gists{/gist_id}","starred_url":"https://api.github.com/users/des-des/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/des-des/subscriptions","organizations_url":"https://api.github.com/users/des-des/orgs","repos_url":"https://api.github.com/users/des-des/repos","events_url":"https://api.github.com/users/des-des/events{/privacy}","received_events_url":"https://api.github.com/users/des-des/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/FAC6/facfaq/labels/help%20wanted","name":"help wanted","color":"159818"},{"url":"https://api.github.com/repos/FAC6/facfaq/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-03T12:39:00Z","updated_at":"2015-12-03T13:40:55Z","closed_at":"2015-12-03T13:40:55Z","body":"## Problem\r\n\r\nI am trying to apply a pattern something like this:\r\n```\r\nvar setThreeNumbersAsync = function(nums, callback) {\r\n  var numbersFetched = 0;\r\n  out = [];\r\n  var next = function(number, index) {\r\n    out[index] = number;\r\n    numbersFetched += 1;\r\n    if (numbersFetched === 3) {\r\n      callback(out);\r\n    }\r\n  };\r\n  setTimeout(function() {\r\n    next(nums[0], 0);\r\n  }, 100);\r\n  setTimeout(function() {\r\n    next(nums[1], 1);\r\n  }, 200);\r\n  setTimeout(function() {\r\n    next(nums[2], 2);\r\n  }, 300);\r\n};\r\n\r\nsetThreeNumbersAsync([0, 1, 2], function(result) {\r\n  console.log('0, 1, 2 set at time 0: ', result);\r\n});\r\n\r\nsetTimeout(function() {\r\n  setThreeNumbersAsync([3, 4, 5], function(result) {\r\n    console.log('3, 4, 5 set at time 0.1: ', result);\r\n  });\r\n}, 50);\r\n```\r\nAs *expected* the out put is this:\r\n```\r\n\"0, 1, 2 set at time 0: \"\r\n[3, 4, 2]\r\n\"3, 4, 5 set at time 0.05: \"\r\n[3, 4, 5]\r\n```\r\nWhat is a nice way to do this. ie `setThreeNumbersAsync` is used/modified in such a way that each call made to it that holds a separate instance of out.\r\n\r\n## possible solutions\r\n * use `new` (but that would upset crockford)\r\n * have an array of arrays for `out`; each outer array referenced by a counter incremented on each call to `setThreeNumbersAsync` (plus some closure trickery)\r\n\r\n## questions\r\n\r\n * Is the second solution the best way to do things without using `new`? \r\n * Does this problem make sense?"}}