From 4f22d6866c052fb5b770ce4f377cecacacd9e6d8 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 23 Dec 2010 00:44:27 +0100 Subject: complete rewrite of documentation generation - romeved mustache.js - unified templates - improved testability of the code --- docs/callback.js | 66 -------------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 docs/callback.js (limited to 'docs/callback.js') diff --git a/docs/callback.js b/docs/callback.js deleted file mode 100644 index 0d0669d1..00000000 --- a/docs/callback.js +++ /dev/null @@ -1,66 +0,0 @@ -function noop(){} - -function chain(delegateFn, explicitDone){ - var onDoneFn = noop; - var onErrorFn = noop; - var waitForCount = 1; - delegateFn = delegateFn || noop; - var stackError = new Error('capture stack'); - - function decrementWaitFor() { - waitForCount--; - if (waitForCount == 0) - onDoneFn(); - } - - function self(){ - try { - return delegateFn.apply(self, arguments); - } catch (error) { - self.error(error); - } finally { - if (!explicitDone) - decrementWaitFor(); - } - }; - self.onDone = function(callback){ - onDoneFn = callback; - return self; - }; - self.onError = function(callback){ - onErrorFn = callback; - return self; - }; - self.waitFor = function(callback){ - if (waitForCount == 0) - throw new Error("Can not wait on already called callback."); - waitForCount++; - return chain(callback).onDone(decrementWaitFor).onError(self.error); - }; - - self.waitMany = function(callback){ - if (waitForCount == 0) - throw new Error("Can not wait on already called callback."); - waitForCount++; - return chain(callback, true).onDone(decrementWaitFor).onError(self.error); - }; - - self.done = function(callback){ - decrementWaitFor(); - }; - - self.error = function(error) { - var stack = stackError.stack.split(/\n\r?/).splice(2); - var nakedStack = []; - stack.forEach(function(frame){ - if (!frame.match(/callback\.js:\d+:\d+\)$/)) - nakedStack.push(frame); - }); - error.stack = error.stack + '\nCalled from:\n' + nakedStack.join('\n'); - onErrorFn(error); - }; - - return self; -} - -exports.chain = chain; -- cgit v1.2.3