Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/q.js/1.0.1/q.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var promises = [];
function doTask(taskId) {
  var deferred = Q.defer(); //init promise
  
  setTimeout(function () {
    
    console.log("Done with " + taskId);
    deferred.resolve("Finished " + taskId);
    
  }, Math.floor(Math.random() * 3000));
  
  
  promises.push(deferred.promise);
}
["task1", "task2", "task3"].forEach(function(task) {
 doTask(task);
});
Q.allSettled(promises).then(function(results) {
  
  console.log("All done");
  
  results.forEach(function(result) {
    console.log(result);
  });
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers