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
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general