improved long polling
This commit is contained in:
parent
a8011462f3
commit
404971ce76
|
@ -228,16 +228,23 @@ public class TelegramAPI implements Runnable {
|
|||
@Override
|
||||
public void run() {
|
||||
start = System.currentTimeMillis();
|
||||
while(run) {
|
||||
long runstart = System.currentTimeMillis();
|
||||
fetchUpdates();
|
||||
fetchedUpdates++;
|
||||
try {
|
||||
int wait = (int) (updateInterval - (System.currentTimeMillis() - runstart));
|
||||
if(wait > 0)
|
||||
Thread.sleep(wait);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
if(longpolling) {
|
||||
while(run) {
|
||||
fetchUpdates();
|
||||
fetchedUpdates++;
|
||||
}
|
||||
} else {
|
||||
while(run) {
|
||||
long runstart = System.currentTimeMillis();
|
||||
fetchUpdates();
|
||||
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() {
|
||||
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) {
|
||||
log.log("error getting updates.", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue