dwf/rva: Refactored async spec logic.

This commit is contained in:
pivotal
2008-12-01 15:15:34 -08:00
parent 3e02023d9f
commit 0ccb6dfc90
3 changed files with 103 additions and 36 deletions

View File

@@ -61,23 +61,25 @@ var expects_that = function (actual) {
/*
* Jasmine spec constructor
*/
var it = function (description, func) {
var that = {
description: description,
func: func,
done: false,
execute: function() {
that.func.apply(that);
}
}
return that;
}
//var it = function (description, func) {
// var that = {
// description: description,
// func: func,
// done: false,
// execute: function() {
// that.func.apply(that);
// }
// }
// return that;
//}
var queuedFunction = function(func, timeout, spec) {
var that = {
func: func,
next: function () {spec.finish()},
execute: function () {
next: function () {
spec.finish(); // default value is to be done after one function
},
execute: function () {
if (timeout > 0) {
setTimeout(function () {
that.func();
@@ -92,22 +94,26 @@ var queuedFunction = function(func, timeout, spec) {
return that;
}
var it_async = function (description) {
var it = function (description) {
var that = {
description: description,
queue: [],
currentTimeout: 0,
done: false,
waits: function (timeout) {
that.currentTimeout = timeout;
return that;
},
resetTimeout: function() {
that.currentTimeout = 0;
},
finish: function() {
that.done = true;
},
done: false,
execute: function () {
if (that.queue[0]) {
that.queue[0].execute();
@@ -116,15 +122,18 @@ var it_async = function (description) {
};
var addToQueue = function(func) {
currentFunction = queuedFunction(func, that.currentTimeout, that);
var currentFunction = queuedFunction(func, that.currentTimeout, that);
that.queue.push(currentFunction);
if (that.previousFunction) {
that.previousFunction.next = function () {
if (that.queue.length > 1) {
var previousFunction = that.queue[that.queue.length - 2];
previousFunction.next = function () {
currentFunction.execute();
}
}
that.resetTimeout();
that.previousFunction = currentFunction;
return that;
}