X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Feuphorik.js;h=b44f04298b8b136542e66f9340cf265bac870609;hp=126f335f5cf2c2a5045d11290b6022c357f593fb;hb=ec0132f1c1f3599d7818a566b08129c994e6647b;hpb=b796253a5f27dc6a9a7ede5713365bc4556377ee diff --git a/js/euphorik.js b/js/euphorik.js index 126f335..b44f042 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -914,6 +914,9 @@ function PageEvent(page, util) // l'objet JSONHttpRequest représentant la connexion d'attente this.attenteCourante = null + + // le multhreading du pauvre, merci javascript de m'offrire autant de primitives pour la gestion de la concurrence... + this.stop = false } /** @@ -921,8 +924,12 @@ function PageEvent(page, util) */ PageEvent.prototype.stopAttenteCourante = function() { + this.stop = true + if (this.attenteCourante != null) + { this.attenteCourante.abort() + } } /** @@ -932,11 +939,13 @@ PageEvent.prototype.stopAttenteCourante = function() */ PageEvent.prototype.waitEvent = function(funSend, funReceive) { - var thisPageEvent = this - this.stopAttenteCourante() + + this.stop = false + + var thisPageEvent = this - // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veux dans l'ordre définit dans le protocole) + // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veut dans l'ordre définit dans le protocole) // TODO : ya pas mieux ? var dataToSend = { @@ -948,6 +957,7 @@ PageEvent.prototype.waitEvent = function(funSend, funReceive) dataToSend[v] = poulpe[v] ;;; dumpObj(dataToSend) + this.attenteCourante = jQuery.ajax({ type: "POST", url: "request", @@ -961,15 +971,24 @@ PageEvent.prototype.waitEvent = function(funSend, funReceive) funReceive(data) // rappel de la fonction dans 100 ms - setTimeout(function(){ thisPageEvent.waitEvent(funSend, funReceive) }, 100); + setTimeout(function(){ thisPageEvent.waitEvent2(funSend, funReceive) }, 100) }, error: function(XMLHttpRequest, textStatus, errorThrown) { - setTimeout(function(){ thisPageEvent.waitEvent(funSend, funReceive) }, 1000); + setTimeout(function(){ thisPageEvent.waitEvent2(funSend, funReceive) }, 1000) } }) +} +/** + * Si un stopAttenteCourante survient un peu n'importe quand il faut imédiatement arreter de boucler. + */ +PageEvent.prototype.waitEvent2 = function(funSend, funReceive) +{ + if (this.stop) + return + this.waitEvent(funSend, funReceive) } ///////////////////////////////////////////////////////////////////////////////////////////////////