WinJS SQLite runAsync all before doing something else

别说谁变了你拦得住时间么 提交于 2019-12-11 04:29:53

问题


I have a collection of INSERT statements that gets run within a SQLite async method:

SQLite3JS.openAsync(path).then(function (db) {
    $.each(sql, function (idx, item) {
        return db.runAsync(item).done(function complete(xhr) {
            var i = 0;
        });
    });
});

I want the collection to be inserted, then do something after this has completed successfully. I tried to follow through on then() promises, but they all get called before the db.runAsync() gets fired.

Is there a clean way to do this? Basically, I have a progress ring that should be removed once all this has completed, but I cannot get this to fire correctly.


回答1:


I think you'll want to use WinJS's ability to join multiple promises together...

SQLite3JS.openAsync(path).then(function (db) {
    var promises = [];
    $.each(sql, function (idx, item) {
        promises.push( db.runAsync(item) );
    });

    return WinJS.Promis.join( promises ).then(
        function success() {
            // all done!
        },
        function error() {
            // something didn't work
        },
    );
});


来源:https://stackoverflow.com/questions/20803684/winjs-sqlite-runasync-all-before-doing-something-else

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!