title: Conditional promises in WinJS
body: <p>I've got two pieces of code which may or may not run when my app starts. Both produce a messageDialog, so the second must wait on the first. I'm trying to use promises to do this but I'm having issues with the returned value. Can someone point me in the right direction? </p>
  
  <pre><code>WinJS.Promise.as()
     .then(function () {
         // readTempFile returns a promise, see code below
         if (localSettings.values["lastContent"] != 0) {
              return readTempFile();
         }else{
              // what am I supposed to return here? false? 
         }
     })
     .then(function () {
         // check for release notes
         if (localSettings.values["release"] == null) {
              var updates = "Updates in this version";
              var msg = new Windows.UI.Popups.MessageDialog(updates, "Updates");
              msg.commands.append(new Windows.UI.Popups.UICommand("OK", null, 0));
              msg.showAsync();
         }
     });
  
  function readTempFile(){
      return new WinJS.Promise(function (complete, error, progress) {
          // is my try / catch block redundant here? 
          try {
              tempFolder.getFileAsync("tempFile.txt")
                  .then(function (file) {
                      file.openReadAsync().done(function (stream) {
                           // do stuff with the file
                      });
                      var msg = new Windows.UI.Popups.MessageDialog("unsaved work", "Warning");
                      msg.commands.append(new Windows.UI.Popups.UICommand("OK", null, 0));
                      msg.showAsync();
                      complete();
                  }, function () {
                      // file not found
                      error();
                  });
          }
          catch (e) {
              logError(e);
              error();
          }
      });
  }
  </code></pre>
  
  <p>If both conditions are true, I get an access denied error. As I understand it, <code>readTempFile()</code> returns a promise object which my first <code>then()</code> statement should accept. But I'm not returning anything if the first conditional is met. I don't think that matters in this case as it just falls through to the next <code>then</code>, but it's not good programming. </p>
  
  <p>EDIT: </p>
  
  <p>Amended the readTempFile function to show that it produces a MessageDialog. </p>