Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "tgb", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "The best choice for your Telegram Bots", | ||
@@ -5,0 +5,0 @@ "homepage": "https://666.io", |
@@ -41,4 +41,2 @@ //----------------------------------------------------- | ||
let stopped = false; | ||
let tick = false; | ||
let tmPolling; | ||
@@ -48,3 +46,3 @@ | ||
runLoadNextTick(); | ||
wait(); | ||
@@ -57,3 +55,3 @@ //----------------]> | ||
stopped = false; | ||
runLoadNextTick(); | ||
wait(); | ||
} | ||
@@ -64,4 +62,6 @@ | ||
stop() { | ||
stopped = true; | ||
clearTimeout(tmPolling); | ||
if(!stopped) { | ||
stopped = true; | ||
clearTimeout(tmPolling); | ||
} | ||
@@ -78,9 +78,2 @@ return this; | ||
function runLoadNextTick() { | ||
if(!tick) { | ||
tick = true; | ||
process.nextTick(load); | ||
} | ||
} | ||
function wait(moreSlowly) { | ||
@@ -93,8 +86,2 @@ if(!stopped) { | ||
function load() { | ||
tick = false; | ||
if(stopped) { | ||
return; | ||
} | ||
bot | ||
@@ -107,28 +94,29 @@ .getUpdates(options) | ||
if(data.length > 0) { | ||
for(let id, d, i = 0, len = data.length; i < len; ++i) { | ||
if(stopped) { | ||
return; | ||
} | ||
if(data.length <= 0) { | ||
wait(); | ||
return; | ||
} | ||
d = data[i]; | ||
id = d.update_id; | ||
for(let id, d, i = 0, len = data.length; i < len; ++i) { | ||
if(stopped) { | ||
return; | ||
} | ||
try { | ||
onMessage.call(instance, d, bot); | ||
options.offset = id + 1; | ||
} catch(e) { | ||
e.data = d; | ||
d = data[i]; | ||
id = d.update_id; | ||
callWatchDog(e); | ||
wait(true); | ||
try { | ||
onMessage.call(instance, d, bot); | ||
options.offset = id + 1; | ||
} catch(e) { | ||
e.data = d; | ||
return; | ||
} | ||
callWatchDog(e); | ||
wait(true); | ||
return; | ||
} | ||
} | ||
load(); | ||
} else { | ||
wait(); | ||
} | ||
wait(); | ||
}) | ||
@@ -140,3 +128,3 @@ .catch(function(error) { | ||
.deleteWebhook() | ||
.then(load) | ||
.then(wait) | ||
.catch(function(e) { | ||
@@ -143,0 +131,0 @@ e.context = error; |
90926
2295