[Pkg-javascript-commits] [node-async] 103/480: Unmemoize can be called with a not memoized function, too.

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:16 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-async.

commit 6b4b0200fa9772dd6a1232456352019f3ed937ac
Author: Balint Erdi <balint at secretsaucepartners.com>
Date:   Thu Oct 6 19:16:50 2011 +0200

    Unmemoize can be called with a not memoized function, too.
---
 lib/async.js       |  6 +++---
 test/test-async.js | 60 ++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/lib/async.js b/lib/async.js
index 3b202b6..6231ec1 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -628,14 +628,14 @@
                 }]));
             }
         };
-        memoized.original = fn;
+        memoized.unmemoized = fn;
         return memoized;
     };
 
     async.unmemoize = function (fn) {
       return function () {
-        return fn.original.apply(null, arguments);
+        return (fn.unmemoized || fn).apply(null, arguments);
       }
-    }
+    };
 
 }());
diff --git a/test/test-async.js b/test/test-async.js
index 4c8e420..ef7a546 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -1254,28 +1254,44 @@ exports['memoize'] = function (test) {
 };
 
 exports['unmemoize'] = function(test) {
-  test.expect(4);
-  var call_order = [];
-
-  var fn = function (arg1, arg2, callback) {
-      call_order.push(['fn', arg1, arg2]);
-      callback(null, arg1 + arg2);
-  };
-
-  var fn2 = async.memoize(fn);
-  var fn3 = async.unmemoize(fn2);
-  fn3(1, 2, function (err, result) {
-      test.equal(result, 3);
-  });
-  fn3(1, 2, function (err, result) {
-      test.equal(result, 3);
-  });
-  fn3(2, 2, function (err, result) {
-      test.equal(result, 4);
-  });
-
-  test.same(call_order, [['fn',1,2], ['fn',1,2], ['fn',2,2]]);
-  test.done();
+    test.expect(4);
+    var call_order = [];
+
+    var fn = function (arg1, arg2, callback) {
+        call_order.push(['fn', arg1, arg2]);
+        callback(null, arg1 + arg2);
+    };
+
+    var fn2 = async.memoize(fn);
+    var fn3 = async.unmemoize(fn2);
+    fn3(1, 2, function (err, result) {
+        test.equal(result, 3);
+    });
+    fn3(1, 2, function (err, result) {
+        test.equal(result, 3);
+    });
+    fn3(2, 2, function (err, result) {
+        test.equal(result, 4);
+    });
+
+    test.same(call_order, [['fn',1,2], ['fn',1,2], ['fn',2,2]]);
+
+    test.done();
+}
+
+exports['unmemoize a not memoized function'] = function(test) {
+    test.expect(1);
+
+    var fn = function (arg1, arg2, callback) {
+        callback(null, arg1 + arg2);
+    };
+
+    var fn2 = async.unmemoize(fn);
+    fn2(1, 2, function(err, result) {
+        test.equal(result, 3);
+    });
+
+    test.done();
 }
 
 exports['memoize error'] = function (test) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git



More information about the Pkg-javascript-commits mailing list