Making asynchronous API calls


#1

Hi all,
Is there a way in C3 to run asynchronous API calls like fetch or evalMetrics ?
As I identified many calls in our applications that are independant independent.

Knowing that the native way in Javascript to do so is like:

   var willWeGet_ = new Promise(function(resolve, reject) {
        resolve(BillingAccount.fetch({limit:1}))      
    }
    );
    
    var willWeGet__ = new Promise(function(resolve, reject) {
        resolve(BillingAccount.fetch({limit:1}))    
    }
    );
    
    
    Promise.all([willWeGet_, willWeGet__]).then(function(values) {
        do_some_stuff(values[1], value[0]);
});

Unfortunately, after some performance analysis on this, using local JS code calls asynchronously, it didn’t show much gain compared to synchronous, I assume calls are stacked to be executed sequentially from a one client in one session; is this right ?

Note: I don’t want to run a Batch Job as neither run-time nor load is big, but as a functional perspective, it’s so important to minimize response time, even for let’s say two fetches, as almost all time is spent on these and very less on scripting.

Thanks in advance.


#2

You can have asynchronous processing with MapReduce or Batch jobs.
In this case your js code, I assume it’s from the UI will:

  1. trigger the job and wait for job.status() to be completed
  2. which will produce some results that you will probably need to store in an entity type (e.g. AsyncJobResult),
  3. then to get this result, your js will have to fetch from this AsyncJobResult.

#3

This is not supported today in the way you mean. Promises are planned as a natively supported feature in a coming release.


#4

Independently, how can I check which JavaScript engine version C3 server is using?
Or ECMA specification JavaScript used. (bear with me as I am not really keen on these concepts.)
Also, I would like to know, no Async API is proposed for now ?

Kind regards.


#5

We are currently using Rhino v1.7.7. It supports some EcmaScript (ES) 6 features but is not fully ES 6 compliant.

A timeframe for async APIs support is not available at this time.


#6

If you really want to invoke an action without synchronously waiting for the action to come back, you could do

ActionQueue.submitAction(TypeRef.make({
      typeName: < Type >
    }), < ActionName >, < context >, < autoCommit >);