LeChris
github.com/habbo-hotel
This is a test function
The results do not return in the order the code is called in. I'm interested in what I'm doing wrong or if this is a possible bug?
Doesn't Return In Order
Does Return In Order
Maybe my understanding of Async/Await is bad - and I'm trying to handle async code in a sync way as each promise does resolve, just not in the intended order.
The results do not return in the order the code is called in. I'm interested in what I'm doing wrong or if this is a possible bug?
Doesn't Return In Order
PHP:
// Async functions
async function one() {
setTimeout(() => {
console.log(1)
return true
}, 5000)
}
async function two() {
console.log(2)
return true
}
async function three() {
setTimeout(() => {
console.log(3)
return true
}, 1500)
}
// Primary Function
async function init() {
let result = {}
result = await one()
result = await two()
result = await three()
console.log('Finished')
}
// Call It
init()
Does Return In Order
PHP:
console.log('\n\n\n\n\n\n\n')// Async functions
async function one() {
return new Promise ((resolve, reject) => {
setTimeout(() => {
console.log(1)
resolve()
}, 10000)
})
}
async function two() {
console.log(2)
return;
}
async function three() {
return new Promise ((resolve, reject) => {
setTimeout(() => {
console.log(3)
resolve()
}, 1000)
})
}
// Primary Function
async function init() {
await one()
await two()
await three(0)
}
// Call It
init()
Maybe my understanding of Async/Await is bad - and I'm trying to handle async code in a sync way as each promise does resolve, just not in the intended order.
Last edited: