Skip to content

Instantly share code, notes, and snippets.

@peutetre
Created December 2, 2011 21:18
Show Gist options
  • Select an option

  • Save peutetre/1424872 to your computer and use it in GitHub Desktop.

Select an option

Save peutetre/1424872 to your computer and use it in GitHub Desktop.
Stupid q.js test (serial join)
<!DOCTYPE html>
<html>
<head>
<script src="q.js"></script>
<script>
function add(millis, answer, msg) {
const defer = Q.defer();
setTimeout(function() {
if (answer instanceof Array) {
answer.push(msg);
}
else {
answer = [];
answer.push(msg);
}
console.log(msg);
defer.resolve(answer);
}, millis);
return defer.promise;
}
function test1(done) {
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].forEach(function (value) {
done = Q.when(done, function (answer) {
return add(1000, answer, value);
});
});
return done;
}
function doit() {
Q.when(
test1(),
function (answer) {
console.log(answer);
}
);
}
</script>
</head>
<body onload="doit()"></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment