Hi Florent,

As far as I know, event-driven or async processing simply doesn’t work in SJS..

Cheers,
Geert

From: 
<general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>>
 on behalf of Florent Georges <li...@fgeorges.org<mailto:li...@fgeorges.org>>
Reply-To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Date: Tuesday, June 20, 2017 at 1:13 PM
To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Subject: [MarkLogic Dev General] SJS: use async callback value in the response 
body

Hi,

I am using a JavaScript library that uses callbacks intensively in its API to 
cope with async processing.  As it is usually the case in the Node universe.

One of the functions is essentially a source for data, which might require an 
async processing to get read.  So it does not return the data, it provides it 
instead as parameter to a callback function.

Because of the async nature, it does not return itself anything returned from 
the callback function, as the latter will be called typically after the end of 
completion of the readData call itself.

This represents more or less that situation:

    // imported from a lib, cannot be changed
    function readData(callback) {
       // actually not called directly, but it is lib implem details
       callback({ some: 'data' });
    }

    readData(data => {
       // how to use `data` in the response sent to the client?
       return 'Response body: ' + data.some;
    });

The data must be used in the response returned to the client, but there is no 
way to use it, per se, in the return value of the script.  Because this is 
quite a common pattern in server-side JavaScript, I thought maybe there is a 
pattern addressing the issue in MarkLogic?

Any thought on this?

Regards,

--
Florent Georges
H2O Consulting
http://h2o.consulting/


_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to