Permalink
Browse files

readme

  • Loading branch information...
rsms committed Feb 20, 2010
1 parent d8abc93 commit 20ef416d2bdff0ea6d7be81098613a18a2f4da03
Showing with 13 additions and 0 deletions.
  1. +13 −0 README.md
View
@@ -25,6 +25,19 @@ A `promise` can either wrap an arbitrary operation, or it can be used as a stand
If an error occurs in the middle of the chain (e.g. at fs.stat), the chain
is broken and the outer promise is closed (called) with the error.
+To transform or operate on intermediate return values, you can pass a regular function to `then`:
+
+ promise(fs.stat, __filename)
+ .then(function(stats){
+ if (!stats.isFile())
+ throw new Error('not a file');
+ return promise(fs.cat, __filename)
+ })
+ (function(err, data){
+ if (err) throw err;
+ else sys.puts('successfully read '+data.length+' bytes.');
+ })
+
### Stand-alone promises and closing:
function myAsyncFunction(fn) {

0 comments on commit 20ef416

Please sign in to comment.