我写了下面的代码:为什么'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发生?为什么我会在控制台中获得“[功能]”?