Windows 8 How to Join Promises

by sunil ravulapalli /13. January 2012 19:53 /windows8 /Comments (0)

This code was tested on Windows 8 developer preview and may be outdated by the time future versions are released.

Currently I am using promises[0]._value.responseText to access by response. But it doesn't feel right at all. I could not yet find any documentation to do it correct way.

 var urls = [
                    "http://dev.virtualearth.net/REST/v1/Locations?q=07008&key=abcdef",
                    "http://dev.virtualearth.net/REST/v1/Locations?q=08830&key=abcdef"
                ];
        
 var promises = urls.map(function (url) {
            return WinJS.xhr({ url: url });
 });
    
 WinJS.Promise.join(promises).then(function () {
                contentPara.innerHTML += promises[0]._value.responseText+ '
'; contentPara.innerHTML += promises[1]._value.responseText+ '
'; }, handleError); function handleError() { writeContent('Error geocoding, please try again later.'); }
blog comments powered by Disqus