how to synchronised read or write file on metro style applications by JavaScript?

Answered how to synchronised read or write file on metro style applications by JavaScript?

  • 2012年4月18日 13:34
     
     

    I want to load a .xml file and read  information in it, then write the information to another .txt file.

    just like we can use "await" operate file in  c#,how to  do that in JavaScript?

全部回复

  • 2012年4月18日 16:29
     
     已答复

    The await keyword is just a convenient shortcut for dealing with async operations. We don't have something quite so convenient in the JavaScript language projection, so you'll need to place the write function inside the completed handler of the async read function.

    So for your operation, in pseudo code:

    myXmlFile.readAsync()
        .then(function (fileReadResults) {
            return myTextFile.writeAsync(fileReadResults);
        })
        .done();

    In short, it's just an instance of handling a series of async operations through chained promises.

  • 2012年4月23日 13:43
     
     
    Sorry for hijacking the thread, but its somehow related... Is there any way already in WinRT to synchronize write operations? Like for a a logwriter, that gets very frequent calls but cannot write out the log entries as fast as they come in. Any queuing already available?
  • 2012年4月23日 15:53
     
     
    Phil--it would be best if you posted this as a new question in the forums, and included a link to this thread. Otherwise it won't get seen by the moderators who are the ones who generally do most of the answering and can research questions like yours.