Unified async and async queueable function running code
This commit is contained in:
@@ -40,11 +40,10 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
|
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
|
||||||
var queueableFn = queueableFns[iterativeIndex];
|
var queueableFn = queueableFns[iterativeIndex];
|
||||||
if (queueableFn.fn.length > 0) {
|
var completedSynchronously = attempt(queueableFn);
|
||||||
attemptAsync(queueableFn);
|
|
||||||
|
if (!completedSynchronously) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
attemptSync(queueableFn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,15 +52,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
self.onComplete();
|
self.onComplete();
|
||||||
});
|
});
|
||||||
|
|
||||||
function attemptSync(queueableFn) {
|
function attempt(queueableFn) {
|
||||||
try {
|
|
||||||
queueableFn.fn.call(self.userContext);
|
|
||||||
} catch (e) {
|
|
||||||
handleException(e, queueableFn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function attemptAsync(queueableFn) {
|
|
||||||
var clearTimeout = function () {
|
var clearTimeout = function () {
|
||||||
Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
||||||
},
|
},
|
||||||
@@ -69,9 +60,12 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
onException(error);
|
onException(error);
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
next = once(function () {
|
cleanup = once(function() {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
self.globalErrors.popListener(handleError);
|
self.globalErrors.popListener(handleError);
|
||||||
|
}),
|
||||||
|
next = once(function () {
|
||||||
|
cleanup();
|
||||||
self.run(queueableFns, iterativeIndex + 1);
|
self.run(queueableFns, iterativeIndex + 1);
|
||||||
}),
|
}),
|
||||||
timeoutId;
|
timeoutId;
|
||||||
@@ -92,11 +86,18 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
queueableFn.fn.call(self.userContext, next);
|
if (queueableFn.fn.length === 0) {
|
||||||
|
queueableFn.fn.call(self.userContext);
|
||||||
|
} else {
|
||||||
|
queueableFn.fn.call(self.userContext, next);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleException(e, queueableFn);
|
handleException(e, queueableFn);
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onException(e) {
|
function onException(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user