【发布时间】:2021-07-30 12:33:02
【问题描述】:
所以我有一个返回值的函数 例如:
let value= function () =>{
//basically getting values from an api
let get = axios.get("example.com").then(res=>{
Value = res
})
// Value is the value that had been retrieved from a Get request from an API
return Value ;
}
module.export = {value}
^^ 那是第二个文件中的第一个文件,我想获取使用它们的值,这里的问题是我第一次使用该函数:
const first_file = require("./first_file")
first_file.then(res=>{
console.log(res)
})
我第一次使用该函数时会很好,但有时如果出现错误,我会使用 try catch 方法再次调用该函数,这将返回我第一次得到的相同响应
对不起,不好的解释
【问题讨论】:
-
我认为您只需导出
get,然后执行类似first_file.then(res => ..., err => ...);之类的操作。 -
你好,所以当另一个函数发生错误时,我正在召回该函数,谢谢
标签: javascript node.js async-await promise