코드에서 비동기 함수에 복잡한 문제가 있습니다. 개체가있어서 다른 기능 (애니메이션, 콘텐츠 분석 등)을 적용해야합니다.jQuery.Deferred in recursive cycle
this.buildChain = function (data, func, func_at, func_after) {
//first I launch some function
func.apply(animData, arguments);
//then I filter an array of objects
data.filter(function(e){
if(e.trigger == 'at' && e.link == animData.id) return true;
}).forEach(function(e){
//And apply the function to all objects that've been filtered
//These functions apply at the same time as the first, "func"
func_at.apply(e, arguments);
});
//When my "func" and all "func_at" operations are resolved, I have
//to filter my array again and execute "func_after" function
data.filter(function(e){
if(e.trigger == 'auto' && e.link == animData.id) return true;
}).forEach(function(e){
func_after.apply(e, arguments);
});
};
것은 내가 재귀 기능이 buildChain
기능을 적용 할 필요가 있다는 것입니다 :
function playChain(animData){
function func() {
//some action
}
function func_at() {
playChain(this);
}
function func_after() {
playChain(this);
}
s.buildChain(data, animData, func, func_at, func_after);
}
, 어떻게 든 jQuery.Deffered()
개체에 해결 될 수 있지만이 올 때 나는 박히면서 그 재귀 사이클. 실제 사슬은 객체에서 시작될 수 있기 때문에 func_at
, 그 다음에 하나가 func_after
이고, 다시 func_at
이됩니다.
(1) 기능이 비동기입니까? (2) 당신은 정말로'인수'(3 곳)를 의미합니까, 아니면 그 의사 코드입니까? –
아니요, 의사 코드가 아닙니다. 데이터는 Object이며 func, func_at 및 func_after입니다. 일부 임의의 함수가 인수로 전달됩니다. "func"와 "func_at"가 동시에 시작되면 "func_after"는 다른 모든 작업이 완료된 후에 시작해야합니다. – AlexNasonov
그래서 "func"와 "func_at"은 비동기식입니다 - 약속을 되 돌리십니까? –