var content = 'now - not content';
const getHtmlCode = function(){
request(url, function(req, resp, body){
content = body;
});
return content;
};
console.log(getHtmlCode()); // >> now - not content
在控制台中我可以看到/now - not content/因为对站点的请求需要 2-3 秒。
糟糕的解决方案:我可以在返回时添加 setTimeout,但这是非常糟糕的方式。
我怎样才能在返回内容之前等待?