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.
Commit
f2601541147a5f01db795f1d1ae531393e06336e632d1f41a25ba1ef13c23a05
Parent
ce988f94077314f…
1 file changed
+6
-3
+6
-3
| --- tools/chat.tcl | ||
| +++ tools/chat.tcl | ||
| @@ -259,17 +259,20 @@ | ||
| 259 | 259 | r.appendChild(td); |
| 260 | 260 | if( m.xfrom==_me ){ |
| 261 | 261 | td.appendChild(document.createTextNode('me')) |
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | - setTimeout(poll, 10); | |
| 265 | 264 | } |
| 266 | 265 | async function poll(){ |
| 266 | + if(poll.running) return; | |
| 267 | + poll.running = true; | |
| 267 | 268 | 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) | |
| 269 | 272 | } |
| 270 | - poll(); | |
| 273 | + setInterval(poll, 1000); | |
| 271 | 274 | })();</script> |
| 272 | 275 | } |
| 273 | 276 | |
| 274 | 277 | # Make sure the chat database exists |
| 275 | 278 | sqlite3 db [chat-db-name] |
| 276 | 279 |
| --- 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 |