[英]Async object Promise as Callback
當我將這個 function 作為回調 [object Promise] 運行時,為什么我會變成這樣? 我使用 Mitivit4min ( Github ) 的 Ts3 nodejs 框架
這里我嘗試了一些代碼(返回值 = [object Promise])
async function getChannelName(cid) {
await teamspeak.getChannelByID(cid).then(data => {
return data.name;
});
};
如何將此值轉換為具有“我的酷頻道”之類的值的字符串
此致
An async
function always returns a Promise
by design and your getChannelName
function has no return statement, so the promise is never resolved. 此外,您還混合了一些await
和.then()
語法,您只需要其中一個。
async function getChannelName(cid) {
const data = await teamspeak.getChannelByID(cid);
return data.name;
};
const name = await getChannelName(123); // name has the channel name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.