node: remove asyncStack

Now that the context stores the active execution stack, and because
removeAsyncListener() always removed the AsyncListener from the queue
and the stack, there's no need to keep a stack around anymore. Instead
the active asyncQueue and the currentContext is able to handle it all.

Signed-off-by: Forrest L Norvell <ogd@aoaioxxysz.net>
This commit is contained in:
Trevor Norris 2014-01-21 15:03:12 -08:00
parent f32c1ffe56
commit e6016dae34

View File

@ -260,8 +260,7 @@
// arrays. Please *do not* change these to simple bracket notation. // arrays. Please *do not* change these to simple bracket notation.
// Track the active queue of AsyncListeners that have been added. // Track the active queue of AsyncListeners that have been added.
var asyncStack = new Array(); var asyncQueue = new Array();
var asyncQueue = undefined;
// Keep the stack of all contexts that have been loaded in the // Keep the stack of all contexts that have been loaded in the
// execution chain of asynchronous events. // execution chain of asynchronous events.
@ -320,18 +319,13 @@
contextStack.push(currentContext); contextStack.push(currentContext);
currentContext = ctx; currentContext = ctx;
asyncStack.push(asyncQueue);
asyncQueue = new Array();
asyncFlags[kHasListener] = 1; asyncFlags[kHasListener] = 1;
} }
function unloadContext() { function unloadContext() {
currentContext = contextStack.pop(); currentContext = contextStack.pop();
asyncQueue = asyncStack.pop();
if (typeof currentContext === 'undefined' && if (currentContext === undefined && asyncQueue.length === 0)
typeof asyncQueue === 'undefined')
asyncFlags[kHasListener] = 0; asyncFlags[kHasListener] = 0;
} }
@ -549,11 +543,6 @@
// Add a listener to the current queue. // Add a listener to the current queue.
function addAsyncListener(callbacks, data) { function addAsyncListener(callbacks, data) {
if (!asyncQueue) {
asyncStack.push(asyncQueue);
asyncQueue = new Array();
}
// Fast track if a new AsyncListenerInst has to be created. // Fast track if a new AsyncListenerInst has to be created.
if (!(callbacks instanceof AsyncListenerInst)) { if (!(callbacks instanceof AsyncListenerInst)) {
callbacks = createAsyncListener(callbacks, data); callbacks = createAsyncListener(callbacks, data);
@ -580,34 +569,21 @@
return callbacks; return callbacks;
} }
// Remove listener from the current queue and the entire stack. // Remove listener from the current queue. Though this will not remove
// the listener from the current context. So callback propagation will
// continue.
function removeAsyncListener(obj) { function removeAsyncListener(obj) {
var i, j; for (var i = 0; i < asyncQueue.length; i++) {
if (asyncQueue) {
for (i = 0; i < asyncQueue.length; i++) {
if (obj === asyncQueue[i]) { if (obj === asyncQueue[i]) {
asyncQueue.splice(i, 1); asyncQueue.splice(i, 1);
break; break;
} }
} }
}
// TODO(trevnorris): Why remove the AL from the entire stack? if (asyncQueue.length > 0 || currentContext !== undefined)
for (i = 0; i < asyncStack.length; i++) {
if (asyncStack[i] === undefined)
continue;
for (j = 0; j < asyncStack[i].length; j++) {
if (obj === asyncStack[i][j]) {
asyncStack[i].splice(j, 1);
break;
}
}
}
if ((asyncQueue && asyncQueue.length > 0) ||
(currentContext && currentContext._asyncQueue.length))
asyncFlags[kHasListener] = 1; asyncFlags[kHasListener] = 1;
else
asyncFlags[kHasListener] = 0;
} }
}; };