Fossil SCM

chat: experimentally changed poll() to use setInterval() instead of setTimeout() to attempt to automatically re-activate a connection if it's killed due to a timeout or (maybe) system sleep/resume.

stephan 2020-12-22 10:32 chatroom-dev
Commit f2601541147a5f01db795f1d1ae531393e06336e632d1f41a25ba1ef13c23a05
1 file changed +6 -3
+6 -3
--- tools/chat.tcl
+++ tools/chat.tcl
@@ -259,17 +259,20 @@
259259
r.appendChild(td);
260260
if( m.xfrom==_me ){
261261
td.appendChild(document.createTextNode('me'))
262262
}
263263
}
264
- setTimeout(poll, 10);
265264
}
266265
async function poll(){
266
+ if(poll.running) return;
267
+ poll.running = true;
267268
fetch("%string($pollurl)/" + mxMsg)
268
- .then(x => x.json()).then(y => newcontent(y));
269
+ .then(x=>x.json())
270
+ .then(y=>newcontent(y))
271
+ .finally(()=>poll.running=false)
269272
}
270
- poll();
273
+ setInterval(poll, 1000);
271274
})();</script>
272275
}
273276
274277
# Make sure the chat database exists
275278
sqlite3 db [chat-db-name]
276279
--- tools/chat.tcl
+++ tools/chat.tcl
@@ -259,17 +259,20 @@
259 r.appendChild(td);
260 if( m.xfrom==_me ){
261 td.appendChild(document.createTextNode('me'))
262 }
263 }
264 setTimeout(poll, 10);
265 }
266 async function poll(){
 
 
267 fetch("%string($pollurl)/" + mxMsg)
268 .then(x => x.json()).then(y => newcontent(y));
 
 
269 }
270 poll();
271 })();</script>
272 }
273
274 # Make sure the chat database exists
275 sqlite3 db [chat-db-name]
276
--- tools/chat.tcl
+++ tools/chat.tcl
@@ -259,17 +259,20 @@
259 r.appendChild(td);
260 if( m.xfrom==_me ){
261 td.appendChild(document.createTextNode('me'))
262 }
263 }
 
264 }
265 async function poll(){
266 if(poll.running) return;
267 poll.running = true;
268 fetch("%string($pollurl)/" + mxMsg)
269 .then(x=>x.json())
270 .then(y=>newcontent(y))
271 .finally(()=>poll.running=false)
272 }
273 setInterval(poll, 1000);
274 })();</script>
275 }
276
277 # Make sure the chat database exists
278 sqlite3 db [chat-db-name]
279

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button