Im quite familiar with javascript but I'm a bit confuse with Promise, Async/Await
How do I add async/await to modify a promise data and return the original Promise
e.g.
this working fine
function test() {
const data = {
sample: 1,
test: 2
}
const prom = Promise.resolve(data)
prom.then( data => {
data.sample = 5
})
return prom
}
test().then( data => {
console.log( data )
})
//output: {sample: 5, test: 2}
but if I do async/await to modify the promise data, the original data seems to output before the promise is modified e.g.
function test() {
const data = {
sample: 1,
test: 2
}
const prom = Promise.resolve(data)
prom.then( async data => {
data.sample = await 5
})
return prom
}
test().then( data => {
console.log( data )
})
//output: {sample: 1, test: 2}