windows store app promise

Promise.any ---- 参数是一个promise的数组。any的作用就是 promise 数组中任意一个 promise 执行完毕,就会执行 done内的函数

(function () {
    "use strict";

    WinJS.Binding.optimizeBindingReferences = true;

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                var promiseArr = [];
                var url = 'https://files.cnblogs.com/Mr-Joe/a.js';
                var url2 = 'https://files.cnblogs.com/Mr-Joe/a2.js';
                var success = function (text) {
                    var a = JSON.parse(text.responseText);
                }

                var getData = function (url) {
                    promiseArr.push(WinJS.xhr({
                        url: url
                    }))
                }

                getData(url2);
                getData(url);

                WinJS.Promise.any(promiseArr).done(function (result) {
                    var primiseIndex = result.index;  //the index of  fullfilled promise.


                });
            }
        }
        args.setPromise(WinJS.UI.processAll());

    };
    app.start();
})();

Promise.join 

Promise.any ---- 参数是一个promise的数组。any的作用就是 promise 数组所有的 promise 执行完毕,才会执行 done内的函数

 

 

posted @ 2013-07-16 17:30  高捍得  阅读(231)  评论(0编辑  收藏  举报