【发布时间】:2014-02-25 05:28:52
【问题描述】:
我在这里查看 Q 库:https://github.com/kriskowal/q
这就是我编写带有回调的函数的方式:
function token(callback) {
require('crypto').randomBytes(34, function(ex, buf) {
var token = buf.toString('hex');
callback(token);
})
}
exports.generateToken = token;
那么我会:
require('../models/security').generateToken(function (token) {
console.log("here " + token)
})
我将如何使用 .then 来做到这一点?
【问题讨论】: