Browse files

fleshing out promises section in README

  • Loading branch information...
1 parent 115169b commit 0835b73a6cdd42f522d1068c70f44b9f9af10c74 @nrstott committed Dec 9, 2011
Showing with 26 additions and 0 deletions.
  1. +26 −0
@@ -261,6 +261,9 @@ user-land applications and frameworks are free to employ higher-level abstractio
* Listener: A function listening for the resolution or rejection of a Promise.
* Resolve: A successful Promise is 'resolved' which invokes the success listeners that are waiting and remembers the value that was resolved for future success listeners that are attached.
* Reject: When an error condition is encountered, a Promise is 'rejected' which invokes the error listeners that are waiting and remembers the value that was rejected for future error listeners that are attached.
+* Callback: A function executed upon successful resolution of a Promise.
+* Errback: A function executed when a Promise is rejected
+* Progressback: A function executed to provide intermediate results of a Promise.
### How Promises Work
@@ -321,6 +324,29 @@ value. The callback will be executed for success for a resoled promise or for th
q.when(p, function() { console.log('Success'); });
p.then(function() { console.log('Success'); });
+### Bubbling
+Promises can be 'bubbled'. The return value of a callback becomes the value of an external promise. The same is true of errbacks.
+ function bubble(p) {
+ return p.then(function() {
+ // Assume makePromise is a function that returns a promise for an asyncronous operation.
+ // The value of makePromise when resolved becomes the resolution of the `bubble` function as well.
+ return makePromise();
+ });
+ }
+Bubbling errbacks is paralell to having a try/catch at a higher level handle errors at a lower level.
+ p.then(function(url) {
+ return request(url).then(function() {
+ throw 'error';
+ });
+ }, function(err) {
+ // Will handle the error that occurs in the callback of `request.then`.
+ console.log(err);
+ });
JSGI stands for JavaScript Gateway Interface. It is an interface between web applications and web servers. It is similar to

0 comments on commit 0835b73

Please sign in to comment.