node js is not waiting for postgres queries

44 views
Skip to first unread message

Ersin Demirtas

unread,
Mar 11, 2015, 1:56:51 PM3/11/15
to nod...@googlegroups.com
I have following steps all in one function

        step 1 - input validation
        step 2 - building db query for substring search
        step 3 - query from db - adverts and users (uses the query build in step 2) 1st query
        step 4 - query from db - advert images (uses the results from step 3) 2nd query
        last step - output xml

{ '@': { id: 'BR617' },
  type: 'babysitter',
  title: '',
  description: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.',
  price: 28,
  postcode: 'SE9 6JY',
  latitude: 51.458798,
  longi




When I console.log(row) in step 3 the log is displayed after last step. 
---------------------

I tried using q to run like synchronize but step 3 console.log(row) is still displayed after last step. 


thanks guys.

// ravi

unread,
Mar 11, 2015, 2:03:55 PM3/11/15
to nod...@googlegroups.com
My guess is that your issue likes in the way you are using Q/promises. A query from a DB is typically an asynchronous operation, so while step 3 is waiting on a response step 4 will run, and when that is waiting for a response, the last step will be executed. Using Q will indeed help you make them run in sequence. If you can can share the relevant code we can try to figure out what’s off.

—ravi


Reply all
Reply to author
Forward
0 new messages