The GetEntity schema works asynchronously. Can we make GetEntity work synchrounously?

Question

The getEntity method of the EntitySchemaQuery class works asynchronously. Can we make the getEntity method work synchronously?

Answer

The getEntity method of a customer EntitySchemaQuery is designed for asynchronous use only. Nevertheless, you can imitate synchronous behavior via Terrasoft.chain - see below:

getMyEntity: function(callback) {
    var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {
        rootSchemaName: schemaName
    });
    ...
    esq.getEntity(recordId, function(response) {
        ...
        if (callback) {
            callback.call(this);
        }
    }, this)
},
globalMethod: function() {
    Terrasoft.chain(
        function(next) {
            this.getMyEntity(function() {
                next();
            });
        },
        function() {
            this.doAfterGettingEntity();
        },
        this
    );
}

The next parameter of the last method stores link to the following method in the array. Upon implementation, it will be called after the client receives server response.

Terrasoft.chain can contain as many arguments as needed. Do not forget to specify the next argument so that the array does not stop in advance. The last argument transfers the execution context.

Like 2

Like

Share

0 comments
Show all comments