I have a created a promise to retrieve values from a service and then assign them to variables trans
and confidence
, which should be used as transcript
and conf
in the save_data
function. How can I return these values to the calling function and ensure that no other part of the code executes until the promise is successfully resolved?
fetchTransValues() {
return new Promise((resolve, reject) => {
setTimeout(function() {
var trans = this.service.getTranscriptValue();
var confidence =this.service.getConfidenceValue();
}, 1000);
});
}
async save_recording(){
this.fetchTransValues().then(function(message) {
this.answer_loading=true;
let formData=new FormData();
const transcript_arr = [];
const confidence_arr = [];
....
....
this.http.post(this.baseUrl+'api/auth/get-results', formData).subscribe(response => {
});
});
https://i.stack.imgur.com/AKdIp.png
Value inside promise: https://i.stack.imgur.com/aYJ7O.png Any solution to resolve this issue, Thanks