Quantcast
Channel: DreamFactory Forum - Latest posts
Viewing all articles
Browse latest Browse all 5027

NodeJS scripting & async operations

$
0
0

Hi,

We're trying to create a custom service using NodeJS in our DreamFactory 2.2.0 server, but we have a problem with asynchronous operations. It seems that the execution of the script finishes without waiting for asynchronous operations to finish.

For example, when using the following code which uses promises:

myApi.authentication
    .login("mylogin", "mypassword")
    .then(function(result) {
        console.log("Auth correct: ", result);
        event.response.content = { result: "Authed" };
    });

event.response.content = { result: "Exited" };

It seems that the service always returns { result: "Exited" } but at a later time we can see the "Auth correct" log trace.

Probably this is a similar problem to http://community.dreamfactory.com/t/help-with-my-nodejs-scripting-service/2992

¿How can the service be configured to wait for asynchronous operations?

Thanks in advance.


Viewing all articles
Browse latest Browse all 5027

Trending Articles