javascript - UnhandledPromiseRejectionWarning: TypeError: (intermediate value) is not a function
问题描述
我正在尝试使用 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
s 以避免UnhandledPromiseRejectionWarning
错误。
推荐阅读
- android - 如何修复 Android App 中的此类布局问题
- php - 我可以使用其他编码语言生成 html 代码吗?
- odata - 在 OData 中获取多个主键记录
- angular - Angular 中的代码执行需要更多时间
- css - 如何水平对齐两个 div 并强制内容位于 div 内
- google-bigquery - Bigquery LegacySQL 使用特殊装饰器及时的无效快照@0
- javascript - 多个成员变量
- php - 如何保留我在 CodeIgniter 站点中通过 wordpress 身份验证设置的 $_SESSION 数据?
- sql-server - 是否可以同时使用实体框架和数据库项目?
- angular - 如何让货币管道仅使用国家代码?