Skip to content

Commit

Permalink
faster backoff, tm tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedigerMoeller committed Jan 10, 2016
1 parent 778f2a2 commit 49f96b8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/kontraktor-http/src/main/javascript/js4k/js4k.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ window.jsk = window.jsk || (function () {
var sbIdCount = 1;
var batch = [];


function jsk(){
}

var _jsk = new jsk();

_jsk.futureMap = futureMap; // debug read access

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// fst-Json Helpers

Expand Down Expand Up @@ -395,7 +398,7 @@ window.jsk = window.jsk || (function () {
console.log("old data received:"+sequence+" last:"+lastSeenSequence);
return lastSeenSequence;
}
console.log("resplen:"+respLen);
//console.log("resplen:"+respLen);
for (var i = 0; i < respLen; i++) {
var resp = decodedResponse.seq[i + 1];
if (!resp.obj.method && resp.obj.receiverKey) { // => callback
Expand Down Expand Up @@ -585,6 +588,13 @@ window.jsk = window.jsk || (function () {
if ( ! self.isConnected ) {
setTimeout(self.longPoll,1000);
} else {
var cblen = Object.keys(_jsk.futureMap).length;
console.log("CBMAP SIZE ON LP *** ", cblen );
if ( cblen === 0 ) {
// in case no pending callback or promise is present => skip LP
setTimeout(self.longPoll,2000);
return;
}
var reqData = '{"styp":"array","seq":[1,'+self.lpSeqNo+']}';
var request = new XMLHttpRequest();
request.onload = function () {
Expand All @@ -601,11 +611,11 @@ window.jsk = window.jsk || (function () {
if ( resp && resp.trim().length > 0 ) {
var respObject = JSON.parse(resp);
self.lpSeqNo = processSocketResponse(self.lpSeqNo, respObject, true, self.onmessageHandler, self);
setTimeout(self.longPoll,0);
setTimeout(self.longPoll,0); // progress, immediately next request
} else {
console.log("resp is empty");
setTimeout(self.longPoll,1000);
}
setTimeout(self.longPoll,0); // progress, immediately next request
} catch (err) {
console.log(err);
setTimeout(self.longPoll,3000); // error, slow down
Expand Down

0 comments on commit 49f96b8

Please sign in to comment.