Fix long-polling

This commit is contained in:
Mahdi Dibaiee
2015-07-05 15:38:07 +04:30
parent ac625708f9
commit e036c11152
4 changed files with 8 additions and 25 deletions

View File

@ -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);
});
};