0

Javascript

var denemeSource = new DevExpress.data.DataSource({
                        store: Deneme.db.deneme
                    }).load().done(function (result) {
                        alert("1x");
                    });
var denemeSource1 = new DevExpress.data.DataSource({
                        store: Deneme.db.deneme1
                    }).load().done(function (result) {
                        alert("2x");
                    });
var denemeSource2 = new DevExpress.data.DataSource({
                        store: Deneme.db.deneme2
                    }).load().done(function (result) {
                        alert("3x");
                    });
alert("4x");

If the codes are written in that order in Devextreme mobile, '1x,2x,3x,4x', It does not come as ordered. '4x' becomes the latest.

How do I keep coming sequentially? (1x,2x,3x,4x)

how does the DataSource object work as synchronous ?

1 Answers1

0

I have no experiece with the library you are using; however, i do have experience in native JavaScript. Hopefully, someone with experience with this library can expand my answer to further any information you may need to achieve your goals.

What you are trying to achieve is very easy but you need to first understand how asynchronous functions work.


asynchronous functions(async)

  • May be invoked on another thread (for thread-based deferral mechanisms), so apps must synchronize any resources the callback accesses.
  • Cannot touch anything tied to the original stack or thread, such as local variables or thread-local data.
  • If the original thread held locks, the callback will be invoked outside them.
  • Must assume that other threads or events could have modified the application’s state.

That said, you have 2 choices that come to mind. call the asynchronous functions using a latter method or check if each function has run successfully using a timeout.

I suggest using a latter.

(new DevExpress.data.DataSource({
    store: Deneme.db.deneme
}).load().done(function (result) {
    alert("1x");
    (new DevExpress.data.DataSource({
        store: Deneme.db.deneme1
    }).load().done(function (result) {
       alert("2x");
        (new DevExpress.data.DataSource({
            store: Deneme.db.deneme3
        }).load().done(function (result) {
            alert("3x");
        }));
    }));
}));

using the timeout, you should know that the timeout uses an asynchronous function as well.

var returns = array(false, false, false);
var denemeSource = new DevExpress.data.DataSource({
    store: Deneme.db.deneme
}).load().done(function (result) {
    returns[0] = true;
});
var denemeSource1 = new DevExpress.data.DataSource({
    store: Deneme.db.deneme1
}).load().done(function (result) {
    returns[1] = true;
});
var denemeSource2 = new DevExpress.data.DataSource({
    store: Deneme.db.deneme2
}).load().done(function (result) {
    returns[2] = true;
});

timeout(function(){
    //all functions run successfully
});

function timeout(success_func) {
    setTimeout(function () {
        for(var k in results){
            if(results[k] == false){
                has_false = true;
                break;
            }
        }
        if(has_false)
            timeout();
        else
            success_func();
    }, 1000);
}
  • I solved my problem in another way. I could not solve my problem that you gave solutions but Thanks for the detailed information you gave. – Ersin Ulker Oct 24 '15 at 13:24