Fix long-polling
This commit is contained in:
13
lib/poll.js
13
lib/poll.js
@ -1,19 +1,10 @@
|
||||
export default function poll(bot) {
|
||||
return bot.api.getUpdates(bot.update).then(response => {
|
||||
const again = wait(bot.update.timeout * 1000, bot).then(poll);
|
||||
if (!response.result.length) {
|
||||
return again;
|
||||
return poll(bot);
|
||||
}
|
||||
bot.emit('update', response.result);
|
||||
|
||||
return again;
|
||||
return poll(bot);
|
||||
});
|
||||
}
|
||||
|
||||
const wait = (miliseconds, value) => {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(value);
|
||||
}, miliseconds);
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user