如何在 bluebird 中使用 http。 以下代码不返回任何内容:
var Promise = require('bluebird');
var co = Promise.coroutine;
http = Promise.promisifyAll(require('http'));
co(function*(){
var resp = yield http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg").endAsync();
console.log(JSON.stringify(resp.body));
})();
最佳答案
最好使用请求 promise
var Promise = require('bluebird');
var co = Promise.coroutine;
var rp = require('request-promise');
co(function*(){
var resp = yield rp({uri: 'http://google.com'});
console.log(JSON.stringify(resp));
})();
关于node.js - 如何将 http 模块与 bluebird 协程一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35397549/