Skip to content

Instantly share code, notes, and snippets.

@stbuehler
Created April 20, 2011 21:59
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 stbuehler/932978 to your computer and use it in GitHub Desktop.
Save stbuehler/932978 to your computer and use it in GitHub Desktop.
webos Mojo: Foundations.Control.Future - make nest usable
/* 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