如何使用Node.js停止/重新检查forEach中的数据

时间:2018-07-09 07:57:04

标签: javascript node.js asynchronous callback async-await

我想检查来自数据库的数据是否可用。 我正在使用每个函数来遍历它,但是当前它不检查其同时运行。

同时运行会向我的频道发送大量消息。

在每个循环后如何检查是否存在数据? 这里的任何帮助将非常感激。

Mycode

 con.connect(function(err) {
    if (err) throw err;
    con.query("query for getting results", function (err, result, fields) {
        if (err) throw err;
        var results = result;

        var results = result;
        var found = false;
        if (typeof results != "undefined" && results != null && results.length != null && results.length > 0){
            results.forEach ( row => {

                //codes to execute
                //How can i check after each loop over the results whther its available or not?
            });

        }
        else{
            console.log("hello");
        }


    });
});

0 个答案:

没有答案