Tengo una función en una aplicación de Quasar que necesita llamar a una API web que debo esperar hasta que obtenga los resultados para llamar a la siguiente función. He publicado mi código y estoy seguro de que me faltan algunos await o async o los tengo en el lugar equivocado.
Global ex=''; testFunction3(arg){ console.log(arg) } , testFunction2(){ this.ex = update_Members_data_term("@musc.edu"); }, async testFunction(){ await this.testFunction2() this.testFunction3(this.ex) },Llamada API:
function update_Members_data_term(term) { axios.get( 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi', { params: { db: 'pubmed', api_key: '', retmode: 'json', retmax: 200, term: term } } ).then(async response => { return response.data.esearchresult.idlist; }).catch(error => { console.log(error.response) })}
Gracias por la ayuda.
testFunction2 no devuelve una Promise , por lo que await no hace nada. En realidad estás await null;
Entonces la solución será:
function update_Members_data_term(term) { return new Promise((resolve,reject) => { axios.get( 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi', { params: { db: 'pubmed', api_key: '', retmode: 'json', retmax: 200, term: term } } ).then(async response => { resolve(response.data.esearchresult.idlist); }).catch(error => { reject(error.response) }) }); } async testFunction2(){ this.ex = await update_Members_data_term("email_here"); },await axios.get en lugar de devolver una Promesa, pero no estoy seguro de cuál es la sintaxis.