Answer the question
In order to leave comments, you need to log in
Multiple awaits in a row?
const a = await http.get
const b = await http.get
Answer the question
In order to leave comments, you need to log in
What does "converted to promises" mean? http.get()
in your case, this is the promise.
await is not just syntactic sugar, it is a language construct that blocks any of the following code inside an asynchronous function until the promise passed to it as a parameter has finished executing.
Accordingly, an analogue of your code without using await is
http.get().then(a => http.get().then(b => {
// Здесь дальнейший код
}))
const p = (resolve, reject) => {
setTimeout(() => resolve(new Date()), 2000)
}
const syncFn = () => {
new Promise(p).then(console.log)
new Promise(p).then(console.log)
}
const asyncFn = async () => {
const a = await new Promise(p).then(console.log)
const b = await new Promise(p).then(console.log)
}
syncFn()
// Tue Jul 14 2020 15:17:19
// Tue Jul 14 2020 15:17:19
asyncFn()
// Tue Jul 14 2020 15:17:49
// Tue Jul 14 2020 15:17:51
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question