aboutsummaryrefslogtreecommitdiffstats
path: root/docs/callback.js
diff options
context:
space:
mode:
authorMisko Hevery2010-12-23 00:44:27 +0100
committerMisko Hevery2011-01-10 11:50:11 -0800
commit4f22d6866c052fb5b770ce4f377cecacacd9e6d8 (patch)
tree6bdb1c5eb70cfd7e6bcf143c121c53025a0489a4 /docs/callback.js
parentaab3df7aeaf79908e8b6212288b283adb42b1ce6 (diff)
downloadangular.js-4f22d6866c052fb5b770ce4f377cecacacd9e6d8.tar.bz2
complete rewrite of documentation generation
- romeved mustache.js - unified templates - improved testability of the code
Diffstat (limited to 'docs/callback.js')
-rw-r--r--docs/callback.js66
1 files changed, 0 insertions, 66 deletions
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;