Skip to content

Instantly share code, notes, and snippets.

@guanix
Created February 17, 2010 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guanix/306121 to your computer and use it in GitHub Desktop.
Save guanix/306121 to your computer and use it in GitHub Desktop.
var continuables = require('continuables'), sys = require('sys');
function delay(timeout, fail) {
var continuable = continuables.create();
setTimeout(function () {
if (fail)
continuable.fulfill(new Error('fail'));
else
continuable.fulfill(true);
}, timeout);
return continuable;
}
var c = delay(1000)
.then(function () {
sys.puts('first callback');
return delay(1000, true);
})
.then(function () {
sys.puts('second callback');
return delay(1000);
})
.then(function () {
sys.puts('third callback');
}, function (e) {
sys.puts('this is the common error handler');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment