0

I'm using httpRequestHandlers for all interaction between the web client and Wakanda server. I'm not using a Wakanda connector from server to client.

How do I provide async responses (promises) to the web ui when ssjs calls to other servers wait for a response?

David Ringsmuth
  • 325
  • 1
  • 12

3 Answers3

4

Promises are a client side concern exclusively. You do not need to do anything from Wakanda Server other than return a result (as you already have been doing) using the httpRequestHandler. How you handle the request client side is your choice.

The fact that your server side code is making a request to a third party does not affect how you would approach the browser's async nature (be it promises or callbacks). Your Wakanda Server code will be synchronous and wait for a response. In turn, when the server side request is complete, including the request to the 3rd party, it will respond to your browser.

With Wakanda Server being multi-threaded, synchronous code for the request will not block other requests from being fulfilled.

I hope this helps.

Greg M
  • 125
  • 9
0

Client side calls be made asynchronously like described here: docs To support promises you'll have to use a library like Bluebird and promisify native calls with callbacks to get functions returning promises.

Calling methods async server side in a HTTP request handler is simple enough too. Just don't use return in the main function, but set response.body (and/or response.statusCode, headers...) in your callback. It could look like this:

function myHandler(request, response){
   callAsync(myParam, {onSuccess: function(event){
      response.body = event.result;
   });
}
0

I agree with previous answers that using Promises on the Front part of your application does not need from the backend to offer any special capability.

If you are using Wakanda's REST API you can use the Wakanda JavaScript Client that already exposes a Promise API.

You can visit the quick-start wiki page to learn more.

hamzahik
  • 714
  • 4
  • 7