Created
February 17, 2010 00:17
-
-
Save guanix/306121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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