Permalink
Browse files

update async module

  • Loading branch information...
1 parent 8a31df2 commit 437cdb0eff5ea549d6d59d8a8be0507c5800ee21 @caolan caolan committed Dec 19, 2010
Showing with 28 additions and 7 deletions.
  1. +28 −7 deps/async.js
View
@@ -79,14 +79,14 @@
//// exported async module functions ////
//// nextTick implementation with browser-compatible fallback ////
- async.nextTick = function (fn) {
- if (typeof process === 'undefined' || !(process.nextTick)) {
+ if (typeof process === 'undefined' || !(process.nextTick)) {
+ async.nextTick = function (fn) {
setTimeout(fn, 0);
- }
- else {
- process.nextTick(fn);
- }
- };
+ };
+ }
+ else {
+ async.nextTick = process.nextTick;
+ }
async.forEach = function (arr, iterator, callback) {
if (!arr.length) {
@@ -599,4 +599,25 @@
async.warn = _console_fn('warn');
async.error = _console_fn('error');*/
+ async.memoize = function (fn, hasher) {
+ var memo = {};
+ hasher = hasher || function (x) {
+ return x;
+ };
+ return function () {
+ var args = Array.prototype.slice.call(arguments);
+ var callback = args.pop();
+ var key = hasher.apply(null, args);
+ if (key in memo) {
+ callback.apply(null, memo[key]);
+ }
+ else {
+ fn.apply(null, args.concat([function () {
+ memo[key] = arguments;
+ callback.apply(null, arguments);
+ }]));
+ }
+ };
+ };
+
}());

0 comments on commit 437cdb0

Please sign in to comment.