安裝

shell> npm install q
var fs = require('fs');

fs.readFile('message.txt', 'utf8', function (err, data) {
  if (err) throw err;
  console.log(data);
});

console.log('Complete!');
step1(function (value1) {
    step2(value1, function(value2) {
        step3(value2, function(value3) {
            step4(value3, function(value4) {
                // Do something with value4 
            });
        });
    });
});
Q.fcall(promisedStep1)
.then(promisedStep2)
.then(promisedStep3)
.then(promisedStep4)
.then(function (value4) {
    // Do something with value4 
})
.catch(function (error) {
    // Handle any error from all above steps 
})
.done();

var fs = require('fs');
var Q = require('q');

Q.nfcall(fs.readFile, 'message.txt', 'utf8')
  .then(function(data) { console.log(data); })
  .fail(function (error) { console.log(data); })
  .done();
var Q = require('q');
Q('Complete!').then(console.log);

:books: 參考網站:

powered by Gitbook最後更新: 2017-11-30 14:13:49

results matching ""

    No results matching ""