JavaScript: how to deal with a function that requires a callback or promise?
0 29 Sep 2019 13:24 by u/user9713
I'm using an API that requires a callback or promise (up to the programmer), so I can't run this synchronously.
Here's the flow of my program:
- Receive input and validate it
- Instantiate a class using that input
- Use that class to call the API
- API requires callback or promise, as it takes about 3-5 seconds to query the data
- Program continues on since it's an async operation, but I need to display that query data
- Don't know how to wait for the data to finish, so program goes to outputting data that requires the class
- Program goes to shit since the class instance's field data is undefined
3 comments
0 u/glennvtx 29 Sep 2019 14:12
Await the promise.. that is the point of them?
0 u/user9713 [OP] 29 Sep 2019 14:22
I was using this as a template and it didn't work. It just continued on.
0 u/glennvtx 29 Sep 2019 15:08
I don't see anything wrong there, besides the code being useless i mean..