Q.js - Using deferred

后端 未结 5 1019
南笙
南笙 2021-02-07 11:36

How do I get the value of the text from the example below?

Q.js has an example on using Deferred:

var deferred = Q.defer();
FS.readFile(\"foo.txt\", \"ut         


        
5条回答
  •  野的像风
    2021-02-07 12:29

    You can get the value via the .then() method of a Promise:

    function read() {
        // your snippet here...
    }
    
    read().then(function (text) {
        console.log(text);
    });
    

    Also, error handlers can be passed either as a 2nd argument to .then() or with the .fail() method:

    read().fail(function (err) {
        console.log(err);
    });
    

提交回复
热议问题