improved long polling

This commit is contained in:
mrbesen 2019-02-25 15:59:36 +01:00
parent a8011462f3
commit 404971ce76
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
1 changed files with 18 additions and 11 deletions

View File

@ -228,16 +228,23 @@ public class TelegramAPI implements Runnable {
@Override @Override
public void run() { public void run() {
start = System.currentTimeMillis(); start = System.currentTimeMillis();
while(run) { if(longpolling) {
long runstart = System.currentTimeMillis(); while(run) {
fetchUpdates(); fetchUpdates();
fetchedUpdates++; fetchedUpdates++;
try { }
int wait = (int) (updateInterval - (System.currentTimeMillis() - runstart)); } else {
if(wait > 0) while(run) {
Thread.sleep(wait); long runstart = System.currentTimeMillis();
} catch (InterruptedException e) { fetchUpdates();
break; fetchedUpdates++;
try {
int wait = (int) (updateInterval - (System.currentTimeMillis() - runstart));
if(wait > 0)
Thread.sleep(wait);
} catch (InterruptedException e) {
break;
}
} }
} }
} }
@ -248,7 +255,7 @@ public class TelegramAPI implements Runnable {
private void fetchUpdates() { private void fetchUpdates() {
try { try {
processUpdates(request("getUpdates", "offset=" + msg_offset + "&timeout=" + (longpolling ? updateInterval : 1), true)); processUpdates(request("getUpdates", "offset=" + msg_offset + "&timeout=" + (longpolling ? updateInterval : 1), false));
} catch (IOException e) { } catch (IOException e) {
log.log("error getting updates.", e); log.log("error getting updates.", e);
} }