Async / Await returning Promise <pending> instead of values
See original GitHub issueHi,
There seems to be an issue with Async/Await handling. Code below:
async function getData() {
console.log('logging');
const test = await CSVToJSON().fromFile('./data/hans-puns.csv');
return test;
}
const data = getData();
console logging data shows a Promise
Issue Analytics
- State:
- Created 5 years ago
- Reactions:21
- Comments:21
Top Results From Across the Web
Why is my asynchronous function returning Promise ...
The promise will always log pending as long as its results are not resolved yet. You must call .then on the promise to...
Read more >asynchronous function returning promise pending instead of a ...
In the below code I am making a Server Call using a async/await. Once I get the results I ...
Read more >Promise <pending> - Damaris Göbel
A promise represents a single asynchronous operation that hasn't been completed yet, but is expected in the future.
Read more >Async Function Returns Promise <pending> : r/learnjavascript
Async functions always return promises. then()'s also always return promises. If you are trying to access a value from an async function there's ......
Read more >Why is my asynchronous function returning Promise { pending ...
JavaScript : Why is my asynchronous function returning Promise { pending } instead of a value ? [ Gift : Animated Search Engine ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I might have been unclear in my earlier comment. I never wanted you to try to
await
outside anasync
function. You can’t do that in current Node. What you need to do is wrap yourawait
call inside anasync
function, and then call thatasync
function in the top-level of your script. If you just try to immediately use the output of the async function, it isn’t going to be useful, because it’s going to be a Promise. But I think people got the impression that I was suggesting to use the given code as-is but only adding await, which is not what I meant to say at all.You’re trying to do something like this:
You read my comment and understandably thought I meant to do this:
What I actually meant was to do this:
You don’t need to await on the final
run()
call, since Node won’t exit until its event loop is empty.async functions return promises. you need to do
const data = await getData()
– unless you intend to setdata
at the top level of the code, in which case you can’t await ongetData
and need to console.log from insidegetData
, or log from a different function that callsawait getData()
inside it.