Answer the question
In order to leave comments, you need to log in
How to make it so that after the event is processed, the next iteration in an infinite loop begins?
while(1) {
сonfig.write(request, 'ascii'); //отправка запроса по TCP
// если нет ответа то ждать
}
config.on('data', function(data){ //получение ответа
if(data[18]==DOC_LIST) {
console.log("Список карт: ", data)
}
});
Answer the question
In order to leave comments, you need to log in
Something like this:
checkTCP();
config.on('data', function(data) {
if (data[18] === DOC_LIST) {
console.log("Список карт: ", data);
}
checkTCP();
});
function checkTCP() {
while(true) {
сonfig.write(request, 'ascii');
}
}
Make a request with a promise and use async/await
async function infinityLoop() {
for (; ;) {
const res = await request();
console.log(res)
}
}
function request() {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve(Date.now())
}, 1000)
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question