CC-Archived / promise-as3

Promises/A+ compliant implementation in ActionScript 3.0
167 stars 52 forks source link

Use an object of promises in Promise.all() #46

Open lukefx opened 9 years ago

lukefx commented 9 years ago

So basically the idea is the same as Dojo where we can pass an object to Promise.all() and the results are paired with their keys. With this way I can identify where the result came from.

Instead of an array we use and object

Promise.all({
  tableA: Promise.when(queryTask1.execute(query)),
  tableB: Promise.when(queryTask2.execute(query))
}).then(onTaskResult).otherwise(onTaskFault);

Then we can use the object keys to identify the results

private function onTaskResult(results:Object):void {
  for (var key:String in results) {
    ...
  }
}