我寫了下面的代碼:爲什麼'promisify'會導致節點忽略一個函數?
var express = require('express');
var app = express();
var Promise = require('bluebird');
var counter = {};
counter.num = 0;
function incr(counter) {
counter.num = counter.num + 1;
}
app.get('/check', function(req, res) {
Promise.promisify(console.log)(counter.num)
.then(Promise.promisify(incr)(counter.num))
.then(console.log(counter.num));
res.end("OK");
});
app.listen(4000);
我期待下面的操作發生synchronically: 1.打印counter.num(= 0) 2.增量counter.num 3.打印新的計數器.num(= 1)
這是我得到:
0 [功能]
爲什麼沒有操作2發生?爲什麼我會在控制檯中獲得「[功能]」?