javascript - How do I use an asynchronous value in a function that needs to return synchronously -


this question has answer here:

i feel i'm overlooking here, trying write function returns synchronous value, internally needs data can fetched async:

// gets asynchronously const getvalueasync = promise.resolve('value')  // needs return value synchronously const returnsyncvalue = () => {     // needs async data here     getvalueasync      // modify     // return result sync }  // work: const value = returnsyncvalue() 

i'm using latest version of node. there way of achieving without changing returnsyncvalue's implementation (i.e. making async well)?

short answer: no

long answer:

you can't because when const value = returnsyncvalue(), haven't gotten async value yet. therefore there no value assign.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -