Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Created August 22, 2012 15:37
Show Gist options
  • Select an option

  • Save crazy4groovy/3426872 to your computer and use it in GitHub Desktop.

Select an option

Save crazy4groovy/3426872 to your computer and use it in GitHub Desktop.
function getRandomNumberHigherThanAsync(minimum) {
var someNumber = (Math.random()*20) + minimum;
return {
'then' : function(cb){ return cb(someNumber); },
'val' : someNumber
};
}
function alertMe(num) {
alert(num);
return {
'then' : function(cb){ return cb(num); },
'val' : num
};
}
var a = getRandomNumberHigherThanAsync;
var b = alertMe;
var final1 = a(10).then(b).then(a).then(b).then(a);
alert("final: " + final1.val);
var final2 = a(10).then(b).then(a).then(b).then(a)
.then(function(num) {
var smallNum = num / 2;
alert(smallNum);
return {
'then' : function(cb){ return cb(smallNum); },
'val' : smallNum
};
});
alert("final: " + final2.then(a).val);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment