Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added memoize to README

  • Loading branch information...
commit 8175ac57de9985917c87b3d15faccee7708293d4 1 parent 2bc2ec3
@caolan caolan authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 README.md
View
29 README.md
@@ -95,6 +95,7 @@ So far its been tested in IE6, IE7, IE8, FF3.6 and Chrome 5. Usage:
### Utils
+* [memoize](#memoize)
* [log](#log)
* [dir](#dir)
* [noConflict](#noConflict)
@@ -871,6 +872,34 @@ __Example__
## Utils
+<a name="memoize" />
+### memoize(fn, [hasher])
+
+Caches the results of an async function. When creating a hash to store function
+results against, the callback is omitted from the hash and an optional hash
+function can be used.
+
+__Arguments__
+
+* fn - the function you to proxy and cache results from.
+* hasher - an optional function for generating a custom hash for storing
+ results, it has all the arguments applied to it apart from the callback, and
+ must be synchronous.
+
+__Example__
+
+ var slow_fn = function (name, callback) {
+ // do something
+ callback(null, result);
+ };
+ var fn = async.memoize(slow_fn);
+
+ // fn can now be used as if it were slow_fn
+ fn('some name', function () {
+ // callback
+ });
+
+
<a name="log" />
### log(function, arguments)
Please sign in to comment.
Something went wrong with that request. Please try again.