我目前有一个异步函数,但它只返回Promise { <pending> },而不返回实际的返回值。
我的职能如下:
async function testFunction() {
try {
var resp = await deepai.callStandardApi("sentiment-analysis", {
text: "This is a test.",
});
return resp.output;
}
catch(e) {
console.log(e);
}
}
console.log(testFunction())有人知道我如何返回实际内容而不是Promise { <pending> }吗?
会感谢您的帮助,并感谢您提前为您的时间。
发布于 2020-09-03 02:13:57
要获得真正的值,您应该在另一个异步函数中等待。
经修订的守则:
async function testFunction() {
try {
var resp = await deepai.callStandardApi("sentiment-analysis", {
text: "This is a test.",
});
return resp.output;
}
catch(e) {
console.log(e);
}
}
(async function() {
console.log(await testFunction());
})();https://stackoverflow.com/questions/63715728
复制相似问题