javascript - 从 js.node 中的异步函数导出值
问题描述
我有一个在函数外部声明并添加到 fileActions 函数内部的列表。在我的代码运行完成后,我想在 modules.exports 中导出列表。如果我在 file2.on('finish', function() 下输出列表,我会得到我想要的结果。我的问题是我不知道如何将列表从异步函数中取出并放入 modules.exports。
function getFile(){
let file = fs.createWriteStream(getPath()+"file.json");
request = https.get("https://fileLocation.com/file.json", function(response) {
response.pipe(file);
file.on('finish', function() {
fileActions();
file.close();
})
});
}
代码块将在方法映射内,并将从
module.exports = {
call: function (method, param, response) {
if (methodMap[method]) {
const result = methodMap[method](param, response);
omnis_calls.sendResponse(result, response);
return true;
}
else {
throw Error("Method '" + method + "' does not exist");
}
}
};
解决方案
推荐阅读
- wordpress - 使用 .htacces 在 Wordpress 中删除域名 (TLD) 后的双斜杠
- python-3.x - 指数族删失分布的 MLE
- c# - 如何从匿名类型中选择属性
- php - 访问Web环境之外的文件,软链接;寻找规范的替代品
- sql - 按优先顺序从表中删除重复项
- reactjs - 在 React 构建文件夹中展平构建目录结构
- javascript - Swiper 初始化不起作用(无法读取未定义的属性“推送”)
- react-admin - 如何在 react-admin 的 AutocompleteInput 中发送正确的查询?
- javascript - ReactJS -> 为什么我的本地存储以这种方式存储项目?
- java - 未找到 Android Jetpack CameraX 方法 createSurfaceProvider()