会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
代码改变世界
Cnblogs
Dashboard
Login
Home
Contact
Gallery
Subscribe
RSS
Cat in dotNET
异步调用框架Async.Operation
2009-05-07 11:44
Cat Chen
阅读(
759
) 评论(
0
)
编辑
收藏
举报
Async
=
{
Operation:
function
()
{
var
callbackQueue
=
[];
this
.result
=
undefined;
this
.state
=
"running
"
;
this
.completed
=
false
;
this
.yield
=
function
(result)
{
var
self
=
this
;
setTimeout(
function
()
{
self.result
=
result;
self.state
=
"
completed
"
;
self.completed
=
true
;
while
(callbackQueue.length
>
0
)
{
var
callback
=
callbackQueue.shift();
callback(self.result);
}
}
,
1
);
return
this
;
}
;
this
.addCallback
=
function
(callback)
{
callbackQueue.push(callback);
if
(
this
.completed)
{
this
.yield(
this
.result);
}
return
this
;
}
;
}
}
;
会员力量,点亮园子希望
刷新页面
返回顶部
About