gpt4 book ai didi

javascript - 未处理的PromiseRejection警告: TypeError: (intermediate value) is not a function

转载 作者:太空宇宙 更新时间:2023-11-04 03:17:20 26 4
gpt4 key购买 nike

我试图使用 async/await 调用一个函数 (findNextOper() ),当我调用它时,我收到此错误:

(node:2748) UnhandledPromiseRejectionWarning: TypeError: (intermediate value) is not a function

我尝试在不同位置添加分号,但没有成功。我不知道如何修复它。

//This is where I call the function

function regFasiFineLav(pool,oper){
return new Promise(async (resolve,reject,) => {
...
let nextOper = await findNextOper(pool,op);
...
resolve();
})();
};

//This is the function precedeing the one that trigger the error(findNextOper).
//I pasted because maybe it is related in some way

function StringToTime(stringTime){
return new Promise(async (resolve,reject) => {
stringTime = stringTime.split(":");
resolve(parseInt(stringTime[0])*3600 + parseInt(stringTime[1])*60 + parseInt(stringTime));
})();
};

//This is the function causing the error
function findNextOper(pool,op){
return new Promise(async (resolve,reject) => {
let sql_query = "SELECT TOP 1 oper_num FROM jobroute WHERE job = '" + op.job + "' AND suffix = " + op.suffix + " AND oper_num > " + op.oper_num + " ORDER BY oper_num ASC";
let result = (await pool.request().query(sql_query)).recordset;
if(result.length === 0){
resolve(0);
}else{
resolve(result[result.length-1]);
}
})();
};

我想按顺序执行所有这些函数,因为此任务无法异步完成

最佳答案

问题在于 () 下面的 Promise 构造函数。调用构造函数后删除 () 。将 .catch() 链接到 Promise 以避免 UnhandledPromiseRejectionWarning 错误。

关于javascript - 未处理的PromiseRejection警告: TypeError: (intermediate value) is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54596211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com