最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript 支持鏈?zhǔn)秸{(diào)用的異步調(diào)用框架Async.Operation

 更新時(shí)間:2009年08月04日 00:13:09   作者:  
javascript 支持鏈?zhǔn)秸{(diào)用的異步調(diào)用框架Async.Operation
復(fù)制代碼 代碼如下:

Async = {};
Async.Operation = function(options) {
options = options || {};
var callbackQueue = [];
var chain = (options.chain && options.chain === true) ? true : false;
var started = false;
var innerChain = null;
this.result = undefined;
this.state = "running";
this.completed = false;
this.yield = function(result) {
var self = this;
if (!chain) {
self.result = result;
self.state = "completed";
self.completed = true;
} else {
started = true;
self.result = result;
self.state = "chain running";
self.completed = false;
}
setTimeout(function() {
if (!innerChain) {
while (callbackQueue.length > 0) {
var callback = callbackQueue.shift();
if (chain) {
callbackResult = callback(self.result);
self.result = callbackResult;
if (callbackResult && callbackResult instanceof Async.Operation) {
innerChain = Async.chain();
while (callbackQueue.length > 0) {
innerChain.next(callbackQueue.shift());
}
innerChain.next(function(result) {
self.result = result;
self.state = "completed";
self.completed = true;
return result;
});
callbackResult.addCallback(function(result) {
self.result = result;
innerChain.go(result);
});
}
} else {
callback(self.result);
}
}
if (!innerChain) {
self.state = "completed";
self.completed = true;
}
} else {
while (callbackQueue.length > 0) {
innerChain.next(callbackQueue.shift());
}
innerChain.next(function(result) {
self.result = result;
self.state = "completed";
self.completed = true;
return result;
});
}
}, 1);
return this;
};
this.go = function(initialArgument) {
return this.yield(initialArgument);
}
this.addCallback = function(callback) {
callbackQueue.push(callback);
if (this.completed || (chain && started)) {
this.yield(this.result);
}
return this;
};
this.next = function(nextFunction) {
return this.addCallback(nextFunction);
};
};
Async.chain = function(firstFunction) {
var chain = new Async.Operation({ chain: true });
if (firstFunction) {
chain.next(firstFunction);
}
return chain;
};
Async.go = function(initialArgument) {
return Async.chain().go(initialArgument);
}

相關(guān)文章

最新評(píng)論

海安县| 大方县| 保山市| 天镇县| 五原县| 金昌市| 托里县| 衡山县| 南投县| 永吉县| 长岛县| 临夏县| 福安市| 宜昌市| 来安县| 陆河县| 永修县| 曲阜市| 新竹市| 金平| 太保市| 西城区| 蓬安县| 庆云县| 大庆市| 二连浩特市| 台中市| 女性| 漠河县| 南皮县| 孙吴县| 唐山市| 二连浩特市| 晋中市| 什邡市| 巴中市| 临海市| 张北县| 张掖市| 碌曲县| 南木林县|