I have a very basic query in js with axios
axios.get("...my_url...")
This query is wrapped in a sync function such that :
myFunc: function()
{
axios.get("...my_url...")
.then((response) => this.GLOBAL_MUTABLE_DATA = response.data)
.catch((error) => console.log(error))
.finally()
}
Now i have a code snippet where i must make sure that myFunc
has finished its 'execution' before going to next instruction :
anotherFunc: function(){
myFunc() // will modify the global mutable data
postProcessData() // will post process this.GLOBAL_MUTABLE_DATA.
}
From the code above i need myFunc
to have finished before being able to run postProcessData
and effectively post process the object this.GLOBAL_MUTABLE_DATA
.
Now my question is : Is it possible to do so ?
For instance do you think the following would be appropriate ?
anotherFuncAsyncVersion : async function(){
await myFunc() // will modify the global mutable data
postProcessData() // will post process this.GLOBAL_MUTABLE_DATA.
}
Where the difference with anotherFunc
is that i've added the async
keyword and await
before the execution of myFunc
.
Unfortunately i can't move the operation postProcessData
to the myFunc
. If i could i would have added the call in the then
block but i can't ...