johnballantyne / qbws

A Node.js web service for QuickBooks Desktop Web Connector
MIT License
38 stars 26 forks source link

Can I have an async call to another server to fetch some data inside sendRequestXML method? #1

Closed ashwaniare closed 9 years ago

ashwaniare commented 9 years ago

WHat I want to do is as soon as the sendRequestMethod is triggered by the QWC, is there a way to make an async call to get the actual request data from some other server and then prepare the QBXML and return that?

johnballantyne commented 9 years ago

If you have a module flag that indicates the request data is still being waited on (let's call it dataReady and set it to false by default), then you could have sendRequestXML() continually return 'NoOp' until that flag is true.

If you want the Web Connector to pause for an interval of time (currently 5 seconds) return the string “NoOp”, which will cause the Web Connector to call your getLastError callback: a “NoOp” returned from GetLastError will cause the QBWC to pause updates for 5 seconds before attempting to call sendRequestXML() again.

Currently, buildRequest() just sends some hard-coded requests for testing until I develop a better system for that. But instead, you could have it asynchronously retrieve your data and set dataReady to true upon success.

ashwaniare commented 9 years ago

Thanks for responding @johnballantyne .. So if I create such a flag and return 'NoOp' continuously until the flag is true, do I need to do something in the getLastError method also? I mean do I need to explicitly return 'NoOp' from there also?

ashwaniare commented 9 years ago

@johnballantyne Thanks for the idea..Works like a charm!! :)

johnballantyne commented 9 years ago

As I presume you found out, yes you'd need to return 'NoOp' from getLastError() as well. I'm glad you got it working @ashwaniare!

ashwaniare commented 9 years ago

Yes, you're right.. I missed that part in the QB developer guide.. Thanks!