4

Needed to help a friend with her Bachelor Thesis. She writes in Javascript and needs to synchronously use the result of a postgresql query. The query call is asynchronous.
We did what any person that searches for a dirty solution would do.
We saved the result of a query in a file and load the file when we need it.
Why is Javascript a thing?

Comments
  • 4
    > synchronously

    You're doing something wrong, not JavaScript.
  • 1
    Why not just wait for query to complete? I'm sure there are other ways of monitoring that.
  • 3
    Not a js person but any async implementation would have either a callback parameter to execute when done, some sort of event/signal/message sent when done, or a way to wait for it to be done (i.e. force synchronicity). Any of these can be used to do what you want.

    Speculating further, you can construct a computation pipe which just waits for the async query and processes it whenever it comes through and then just wait for the query result to come through
  • 4
    I think you really need to look at promises, you would execute the query then do your work modifying the Dom or application state
  • 1
    @Npstr I agree. Whatever this is - it has nothing to do with JavaScript.
  • 1
    Promises or callbacks.
Add Comment