Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  29 Oct 2015, Konstantin Olchanski, Info, synchronous ajax deprecated 
    Reply  29 Oct 2015, Amy Roberts, Info, synchronous ajax deprecated 
       Reply  30 Oct 2015, Stefan Ritt, Info, synchronous ajax deprecated 
          Reply  18 Nov 2015, Amy Roberts, Info, synchronous ajax deprecated 
             Reply  18 Nov 2015, Konstantin Olchanski, Info, synchronous ajax deprecated 
                Reply  19 Nov 2015, Amy Roberts, Info, synchronous ajax deprecated 
       Reply  02 Nov 2015, Konstantin Olchanski, Info, synchronous ajax deprecated 
          Reply  17 Nov 2015, Konstantin Olchanski, Info, synchronous ajax deprecated 
             Reply  18 Nov 2015, Amy Roberts, Info, synchronous ajax deprecated 
                Reply  26 Nov 2015, Konstantin Olchanski, Info, browser compatibility test: synchronous ajax deprecated 
                Reply  27 Nov 2015, Konstantin Olchanski, Info, synchronous ajax deprecated 
Message ID: 1139     Entry time: 18 Nov 2015     In reply to: 1137     Reply to this: 1140
Author: Konstantin Olchanski 
Topic: Info 
Subject: synchronous ajax deprecated 
> > Why don't you post the functions here so that we can have a look? 
> Here is (1) my promisified HTTP request function and (2) a function that uses the returned promises to build an asynchronous, sequential chain of requests to Midas.
> 
> In addition to promisifying HTTP requests to Midas, I wanted the Promise.resolve from this function to always return valid JSON.

Thank you very much for posting this code. It is very similar to what I just wrote this morning for the JSON-RPC client library. In my case, the JSON-RPC responses
are much more regular so error handling is simple: a) check HTTP response 200, b) check JSON-RPC reply parses into valid JSON (catch exception), c) check JSON-RPC error status.

> I also wanted the promise to reject if the response from mhttpd indicated
> failure - so that we wouldn't have to rewrite this error checking throughout the code.

Right now the JSON-RPC client library does not check the return status of MIDAS calls themselves, i.e. ODBGet("/nonexistant") will go to Promise.resolve() with
the MIDAS db_find_key() status DB_NO_KEY instead of Promise.reject(). So some error handling in Promise.resolve() is still required.

I am thinking how to make these calls go to the error handler automatically, but there is no obvious solution for ODBMGet(["/runinfo", "/nonexistant"]) - the first path
is a success, the second is a failure, do I fail the entire transaction (i.e. with a JSON-RPC error)? Same for JSON-RPC batch transactions - if one transaction
in the batch fails, do I Promise.reject() all of them?

I guess I could "split hairs" and create a separate Promise for each "atomic" transaction, the Promise mechanism does seem to support that,
but this will create more complexity than I feel comfortable with.

Please take a look at the branch feature/js_promise - mjsonrpc_call() is Promisified (resources/mhttpd.js) and the db_copy() example is Promisified (examples/javascript1/example.html)

K.O.
ELOG V3.1.4-2e1708b5