In my task I want to wait for an asynchronous execution of the function and only then output the result. How can I do this, if my attempts in the code do not work?
CanPrintVS(): boolean {
var result = false;
// at this point I want to wait for the synchronous execution function CheckRefLink :
$.when(this.CheckRefLink().then((r: boolean) => { result = r; }));
return result;
}
private CheckRefLink() {
var def = $.Deferred();
if (this.DOC_RC.KIND_DOC == 3) {
var reflinks = this.DOC_RC.REF_LINK_List;
var waitRefs = $.Deferred();
// 1) In the first case - just a resolve value:
if (reflinks)
waitRefs.resolve(reflinks);
//2) or wait for execution:
else
ds.loadT({ REF_LINK: criteries({ISN_REF_DOC: this.ISN_DOC})
}).promise().then(r => { waitRefs.resolve(r.result); });
waitRefs.done((ns) => {
var linkcl = dm.LINK_CL[ns.ISN_CLLINK];
return def.resolve(linkcl && linkcl.LINK_DIR == 1);
});
}
return def.resolve(false);
}
}