【发布时间】:2019-08-11 02:54:33
【问题描述】:
我目前有以下函数,我想将"aaa"返回给父函数(getStream),这是我的atm代码:
module.exports.getStream = (figure) => {
plotly.plot(figure, imgOpts, function(err, stream) {
if (err) {
console.log(err);
return "error";
}
return "aaa";
});
};
然而,现在它返回undefined。解决该问题的最佳解决方案是什么?
【问题讨论】:
-
“它返回
undefined”是什么意思?它是什么”?您希望plotly.plot调用返回"aaa"还是希望getStream返回它? -
通过在
plotly.plot中使用回调,我假设它是一个异步函数?如果是这样,您需要等待它解决。查看Promises和async/await。
标签: javascript node.js node-modules