The deferred return

Published at: April 4, 2018, 3:34 p.m. in the Documentation

For able to return results with asynchronous actions, a deferred return is implemented in Smappi.

The normal return method looks like this:

function method () {
    return "something";
}

But it is not always possible to return the result immediately, for example:

function method () {
    setTimeout(function () {
        return "something";
    }, 1000);
}

For this purpose, a deferred return was implemented:

function method () {
    var self = this;
    setTimeout(function () {
        self.return("something");
    }, 1000);
}

In the event that the API method does not return anything, or returns "undefined", then Smappi expects that a deferred return will be called. But if you return the result explicitly, then the deferred return will not work.

If no return is made within 20 seconds, Smappi will end with an error, which will be reported to the console.

Additional example

An example of use can be found in the article Working with Database and Container Storage