Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:18:39+00:00 2026-06-17T08:18:39+00:00

After some experimentation, I’ve ended up with the following code, trying to replicate the

  • 0

After some experimentation, I’ve ended up with the following code, trying to replicate the C# await functionality:

var promise = new WinJS.Promise(MyFunc())
    .then(function () {
        // Second function which uses data set-up in the first
        MyFunc2();
    });

‘MyFunc()’ executes correctly, but ‘MyFunc2()’ does not, and the program crashes. What am I misunderstanding about the Promise object?

(This is using Windows 8)

EDIT:

The full code for MyFunc() is now as follows:

function MyFunc() {
    var foldername = "Folder";
    var filename = "readme.xml";

    var promise = Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(foldername).then(function (folder) {
        folder.getFileAsync(filename).then(function (file) {
            var loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings;
            loadSettings.prohibitDtd = false;
            loadSettings.resolveExternals = false;
            Windows.Data.Xml.Dom.XmlDocument.loadFromFileAsync(file, loadSettings).then(function (doc) {
                dataText = doc.getXml();
                xmlDoc = doc;
            }, function (error) {
                output.value = "Error: Unable to load XML file";
                output.style.color = "red";
            }, function (error) {
                output.value = "Error: Unable to load XML file";
                output.style.color = "red";
            })
        })
    });

    return promise;
};

The result now is that ‘MyFunc2()’ executes before ‘MyFunc()’ completes. `MyFunc2() uses the global variable xmlDoc, which is therefore undefined at that time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:18:40+00:00Added an answer on June 17, 2026 at 8:18 am

    You should chain all the promises together and then wait on the final promise.

    function MyFunc() {
        var promise = Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(foldername).then(function (folder) {
            return folder.getFileAsync(filename);
            }).done(function (file) {
                var loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings;
                loadSettings.prohibitDtd = false;
                loadSettings.resolveExternals = false;
                return Windows.Data.Xml.Dom.XmlDocument.loadFromFileAsync(file, loadSettings);
            }).then(function (doc) {
                dataText = doc.getXml();
                xmlDoc = doc;
                return doc; // whatever the result is
            }, function (error) {
                output.value = "Error: Unable to load XML file";
                output.style.color = "red";
            });
        return promise;
    }
    

    Then you can chain on the promise returned by MyFunc:

    var promise = MyFunc().then(function(doc) { MyFunc2(...); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After doing some experimentation with move semantics with an array type I created, I
After some time researching and trying different things I still cannot get my @ExceptionHandler
After some hours of trying, I want to ask how to loop a video
After some code review I removed unnecessary properties which resulted in empty rules. So
I'm a bit confused by the documentation. After some research and experimentation, this is
I had assumed the maximum was 9 but after some experimentation I know it
After several hours of experimentation, I've managed to reduce the problem to the following
Update: After some experimentation, it appears that the thing that is slow is when
After some find and replace refactoring I ended up with this gem: const class
After some desperate assistance regarding prototype.js on Magento. Please see the below product page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.