Answer the question
In order to leave comments, you need to log in
Calling a function again with a promise?
For example, there is this code
function zapros1() {
return new Promise((resolve,reject) => {
request('http://mysite.com/url1', (error,respnse,body) => {
if(error) return reject(error);
return resolve(body);
})
})
}
function zapros2() {
return new Promise((resolve,reject) => {
request('http://mysite.com/url2', (error,respnse,body) => {
if(error) return reject(error);
return resolve(body);
})
})
}
async function main() {
try {
await zapros1();
await zapros2();
} catch (error) {
console.log(error);
}
}
Answer the question
In order to leave comments, you need to log in
let resultZapros1 = false
async function main() {
try {
if (!resultZapros1) {
await zapros1().then((ok) => {
if (ok) {
resultZapros1 = true
}
});
}
await zapros2().then((error) => {
...
});
} catch (error) {
main()
}
}
Я бы сделал как-то так наверно, во втором варианте добавить условие не забудь.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question