この関数は間隔で実行され、実行されると、2つのsettimeoutが設定されます。時刻の前にsettimeoutの非同期関数が呼び出されました
2番目のタイムアウトがトリガーされる前に2番目のタイムアウト後に呼び出される非同期関数が問題です。これは私のコードです。
var runner = Interval.run(function() {
//-212965881
bot.sendMessage('-212965881', "Drop usernames now").then(function(){
ready = 1;
list = {};
console.log(ready);
setTimeout(function(){
return bot.sendMessage('-212965881',"Round has begun. Please start liking now. Leech check will begin in 1 minute");
}, 10000);
}).then(function(){
ready = 0;
setTimeout(function(){
return bot.sendMessage('-212965881',"Leech check has begun!");
}, 15000);
}).then(function(){
//This one fires before 15 seconds
let msg = {chat:{}};
msg.chat.id = '-212965881';
return bot.event('/check', msg);
}).catch(function(err){
console.log(err);
});
}, 20000);
これがどうして起こるかわかりません。おそらくそれについて間違った方法で行っています。 誰もこれにいくつかの光を投げることができますか?ありがとう
[非同期呼び出しから応答を返すにはどうすればよいですか?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous- call) –
'setTimeout()'は後で非同期で実行するようにスケジュールしますが、実行を一時停止しません。また、 'setTimeout()'に渡した関数からの戻り値も無視されます。 – nnnnnn