安裝
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) {
});
});
});
});
Q.fcall(promisedStep1)
.then(promisedStep2)
.then(promisedStep3)
.then(promisedStep4)
.then(function (value4) {
})
.catch(function (error) {
})
.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);
參考網站: