Created
April 20, 2011 21:59
-
-
Save stbuehler/932978 to your computer and use it in GitHub Desktop.
webos Mojo: Foundations.Control.Future - make nest usable
This file contains 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
/* wait for "this" future to reach this point, run "inner" in background; copy result from "inner" future */ | |
Future.prototype.nest = function(inner) { | |
var succ, result, exc, wait = 2, f = this; | |
this.then(function () { | |
f.exception; | |
if (0 == --wait) { if (succ) f.result = result; else f.exception = exc; } | |
}); | |
inner.then(function (future) { | |
if (future.exception) { succ = false; exc = future.exception; } else { succ = true; result = future.result; } | |
if (0 == --wait) { if (succ) f.result = result; else f.exception = exc; } | |
}); | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment