Le processus javascript que je dois mettre en place se découpe en 2 phases successives demandant l'exécution de traitements côté serveur. Les traitements effectués lors de ces 2 phases passent chacun par une pile d'attente.
Je pensais donc utiliser une première fois la fonction setInterval pour vérifier la fin de la première phase puis une seconde fois pour vérifier la fin de la seconde.
Mais ça ne marche pas. Voici le cas de test que j'ai fait pour voir ce qui se passait : je mets a jour un composant text dans ma page pour voir dans quel ordre s'exécutent les actions (nous utilisons une taglib propriétaire, les mises à jour du composant text se font donc à l'aide de méthodes js propriétaires mais le problème n'est pas là)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| // Variable utilisé pour les appels de fonctions à intervalles réguliers
var t_timerA = null;
var t_timerV = null;
var timerA = 0;
var timerV = 0;
function testInterval() {
var obj = mainView.a_searchChildById("avancement");
obj.a_setText("");
var interval = 1000;
appelA(interval);
appelV(interval);
var tmp2 = obj.a_getText();
tmp2 = tmp2 + "/" + "STOP";
obj.a_setText(tmp2);
}
function appelA(interval) {
// POUR LES TESTS
var obj = mainView.a_searchChildById("avancement");
var tmp2 = obj.a_getText();
tmp2 = tmp2 + "/" + "appelA";
obj.a_setText(tmp2);
t_timerA = window.setInterval(function(){methodeCycliqueA()}, interval);
}
function methodeCycliqueA() {
timerA = timerA + 1;
// POUR LES TESTS
var obj = mainView.a_searchChildById("avancement");
var tmp2 = obj.a_getText();
tmp2 = tmp2 + "/A" + timerA;
obj.a_setText(tmp2);
// Cas d'une réponse ok
if (timerA == 5) {
clearInterval(t_timerA);
}
}
function appelV(interval) {
// POUR LES TESTS
var obj = mainView.a_searchChildById("avancement");
var tmp2 = obj.a_getText();
tmp2 = tmp2 + "/" + "appelV";
obj.a_setText(tmp2);
t_timerV = window.setInterval(function(){methodeCycliqueB()}, interval);
}
function methodeCycliqueB() {
timerV = timerV + 1;
// POUR LES TESTS
var obj = mainView.a_searchChildById("avancement");
var tmp2 = obj.a_getText();
tmp2 = tmp2 + "/B" + timerV;
obj.a_setText(tmp2);
// Cas d'une réponse ok
if (timerV == 5) {
clearInterval(t_timerV);
}
} |
Une fois l'exécution de ce code terminé le texte contenu dans mon composant est le suivant :
/appelA/appelV/STOP/A1/B1/B2/A2/A3/B3/B4/A4/A5/B5
Appraremment la fonction appelV commence à s'exécuter alors que la fonction appelA n'est pas terminé.
Partager